Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot assign null to property Basis\\Nats\\Connection::$infoMessage of type Basis\\Nats\\Message\\Info in /var/www/app/vendor/basis-company/nats/src/Connection.php:202 #92

Open
webspec2012 opened this issue Jul 16, 2024 · 2 comments

Comments

@webspec2012
Copy link

No description provided.

@kolyan-r
Copy link

Hello, this error will occur if the client connects to a server that does not support the Nats protocol, since in the Nats protocol the server must send a special message with information about the connection when connecting

This error will also occur if the server does not respond within the allotted time with an information message after initializing the TCP connection

But there is a bug in the code with the processing of the information message, which can clearly be of type null and is assigned to an attribute that cannot be null

# telnet localhost 4222
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
INFO {"server_id":"NBDH32DTZDVFYXP4MNYQZPAFUDSSJWJH23KYOWSEPSPT6K5LTFPX36BN","server_name":"NBDH32DTZDVFYXP4MNYQZPAFUDSSJWJH23KYOWSEPSPT6K5LTFPX36BN","version":"2.10.18","proto":1,"git_commit":"57d23ac","go":"go1.22.5","host":"0.0.0.0","port":4222,"headers":true,"max_payload":1048576,"client_id":13,"client_ip":"172.16.15.1","cluster":"NATS","connect_urls":["172.16.15.2:4222","172.16.15.3:4222","172.16.15.4:4222"],"xkey":"XAGJSQJ7GFMN4PVB6HW366RII7DMIH44HY7HM6HVZIMQLPXHNFMVK44B"}
^]
telnet> quit
Connection closed.

src/Connection.php

Bad code:

$this->infoMessage = $this->getMessage($config->timeout);
assert($this->infoMessage instanceof Info);

Fix option:

$infoMessage = $this->getMessage($config->timeout);

if(! $infoMessage) {
    throw new Exception('INFO message from the server was not received');
}

assert($infoMessage instanceof Info);
$this->infoMessage = $infoMessage;

@nekufa
Copy link
Member

nekufa commented Aug 28, 2024

hi @kolyan-r, would you like to make merge request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants