Raise an error when WebSocket is not cleanly closed#80
Raise an error when WebSocket is not cleanly closed#80baelter merged 2 commits intocloudamqp:mainfrom
Conversation
000c318 to
352a937
Compare
Perhaps it could be done with Toxiproxy: https://github.com/Shopify/toxiproxy#down |
|
@dentarg Using Toxiproxy is a nice idea, but I ran into a couple issues.
Saying all that, there is still I'm happy with just manually testing part of this change. The branch with toxiproxy is here if anyone would like to play more with it: https://github.com/ngbrown-forks/amqp-client.js/tree/error-on-websocket-close-toxiproxy |
|
@ngbrown Thanks for trying, I don't see a way either, not until vitest-dev/vitest#3758 has landed so we can use https://playwright.dev/docs/emulation#user-agent from vitest. Looks like it is possible to make requests with mode |
|
Is there anything else that needs done for this pull request? |
When a WebSocket connection is closed at the network level, there's no error raised by the
AMQPWebSocketClient.This change calls the
onerrormethod when the connection is not cleanly closed. I switched to usingaddEventListenerso therejecthandler wouldn't be replaced by the newclosehandler before theopenokmessage is received.I can test this by restarting a
websocket-relaycontainer in the middle of a session.I don't know how to automatically test this, as the WebSocket needs to be killed. Merely calling
closeon the socket would be considered a clean close.Update: I updated both the WebSocket and Node.js socket clients to set
closedtotruewhen the underlying socket is closed.