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

Failed "connect" call does not close socket #513

Closed
rumata28 opened this issue May 2, 2019 · 5 comments · May be fixed by #584
Closed

Failed "connect" call does not close socket #513

rumata28 opened this issue May 2, 2019 · 5 comments · May be fixed by #584

Comments

@rumata28
Copy link

rumata28 commented May 2, 2019

I am developing integration tests and have problems with negative case testing - my test app never exits.

Steps to Reproduce:

  • Call connect to vhost, for which user does not have permissions
  • See that err callback is called
  • See that NodeJS app just hangs, never exits.

I found that reason is that the following block is only called on timeout:

        sock.end();
        sock.destroy();

And it is never called on other connection errors.

rumata28 pushed a commit to rumata28/amqp.node that referenced this issue May 2, 2019
Add `sock.end` and `sock.destroy` calls for `sock.once('error', ...)`
event handler and for `c.open(fields, ...)` callback - just like it was
done for connection timeout callback.

Resolves amqp-node#513
@xabinapal
Copy link

Just got into this exact issue when trying to connect with a non existent virtual host. Will try to work on a pull request now.

@rumata28
Copy link
Author

Please look my PR. There was some problem in there tests I never managed to fix....

@xabinapal
Copy link

I think I found the issue. Even though what you did was the right thing, it conflicted with other close and error events that were added to the socket. I added some more code based on your PR and now the connect method behaves properly and every test passes.

@aknrdureegaesr
Copy link

aknrdureegaesr commented Nov 8, 2021

Processing leak after rejection

We had a similar problem with an integration test. In our case, the symptom: connect() produces a Promise (or, more precisely, a BlueBird) which is duly rejected a bit later. Our test waits for that rejection to happen. So far, so well. But then, the test framework complains that some background activity is still ongoing, even though the test has finished.

Our expectation is: At the time the promise rejects, all resources have been freed and all background processing pertaining the connection attempt has ceased. Our test framework (we use Jest) waits for another second, and in that second, not all background processing has terminated.

Details

We have a standard RabbitMQ running via

docker run --rm -ti -p 127.0.0.1:5672:5672 -p 127.0.0.1:15672:15672 rabbitmq:3-management

and try to connect to it, using the default existing user and password, but also using a vhost that does not exist.

The pertinent part of our (typescript) code is this:

  const connectionConfig: Options.Connect = {
    protocol: 'amqp',
    hostname: '127.0.0.1',
    port: 5672,
    username: 'guest',
    password: 'guest',
    heartbeat: 2,
    vhost: 'no_such_vhost',
  };
  const amqplibConnection = connect(connectionConfig);
  await expect(amqplibConnection).rejects.toThrowError();

@cressie176
Copy link
Collaborator

amqplib v0.9.0 includes PR 647 which ends and destroys the socket.

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