Git Product home page Git Product logo

Comments (4)

scop avatar scop commented on September 6, 2024

Apparently the same thing also happens in a scenario where a connection + login has succeeded but the channel pool has minFreeChannels > 0, for example if channelFactory in the gist is replaced by:

var channelFactory = new stompit.ChannelPool(connections, {
    minFreeChannels: 1,
});

...as well as servers.connectHeaders set up so that the connection + login actually succeeds.

from stompit.

gdaws avatar gdaws commented on September 6, 2024

Here are the series of commits that fix the problems raised in this issue:

  • 97e2d86 Add support for aborting reconnect
  • 2a1b056 Abort pending connect on channel disconnect
  • 84b6d4c Add ChannelPool#close method
  • 1492a45 Clear timeout when destroy method is called on a connecting socket
  • 3151f42 Destroy transport socket on connect abort

In summary, closing a channel aborts the reconnect occurring in ConnectFailover, and a close method has been added to ChannelPool class that closes any free channels.

In the scenario where you're using a ChannelPool, you need extra signal handlers to shutdown the channel pool.

var closeChannelPool = channelPool.close.bind(channelPool);
process.on("SIGINT", closeChannelPool).on("SIGTERM", closeChannelPool);

from stompit.

scop avatar scop commented on September 6, 2024

Thanks for looking into this, and the fixes.

Maybe I'm missing something wrt the ChannelPool scenario, but code in this gist still does not shut down gracefully on Ctrl-C when there's nothing listening on localhost:61613: https://gist.github.com/scop/aae8d5c3411d1cc92c72

from stompit.

gdaws avatar gdaws commented on September 6, 2024

In my test I had signal handlers for the channel pool and the channel in use, and in the nothing-listening scenario the process terminates immediately after SIGINT. Your code needs a signal handler inside the channelPool.channel callback, and it should only exist for as long as the channel is in use.

Closing the channel pool only closes the current free channels and channels that are later reclaimed. Responsibility to close an occupied channel falls on the user. I now realise this behaviour breaks a key feature of the channel pool, is going to make channels awkward to use and it will probably encourage improper use of channel close. Therefore I intend to change channel pool close so that it closes all channels.

In your code there is a call to close the channel in the send callback - this call is unnecessary and is improper use of channel close. Once the send is complete the channel will be automatically reclaimed by the pool. If a channel is used for a subscription then the channel remains occupied until the user calls unsubscribe. A channel is reclaimed by the pool when all sends and subscribes have finished. A channel user shouldn't be concerned with closing the channel or disconnecting the underlying client.

from stompit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.