Skip to content

Reconnect if beanstalkd stops and restarts #29

Open

Description

@rjrodger

The current version does not seem to support reconnects. Perhaps https://github.com/juliangruber/reconnect-net can be used to do this?

Activity

  1. ceejbot commented on Jul 2, 2014

    @ceejbot
    Owner

    Or this is straightforward to roll by hand if necessary. Good bug.

  2. rjrodger commented on Jul 2, 2014

    @rjrodger
    Author

    I tried rolling it by hand, but I couldn’t get it working and then my brain hurt :)

    Any pointers on how to approach this?

    On 2 Jul 2014, at 18:18, C J Silverio notifications@github.com wrote:

    Or this is straightforward to roll by hand if necessary. Good bug.

    —
    Reply to this email directly or view it on GitHub.

  3. JoshWillik commented on Sep 24, 2015

    @JoshWillik

    +1 I have rolled this by hand, and it makes the code a lot more confusing.

    @ceejbot Do you have plans to add this to fivebeans, or is this something you'd prefer to see implimented in a wrapper library? If it's the later, I can throw something together no problem.

  4. siddo420 commented on Sep 30, 2015

    @siddo420

    +1

    need this behaviour as part of the library itself including reconnect and retry strategies

  5. gtamas commented on Nov 19, 2015

    @gtamas

    +1 I need this too

  6. wltsmrz commented on Feb 19, 2016

    @wltsmrz

    This thing has automatic reconnects and automatically re-uses / re-watches tubes on reconnect. It doesn't have anything advanced like an exponential backoff etc., but seems to work. Would be nice to get more mileage on it

  7. michaelfreund commented on Jun 7, 2016

    @michaelfreund

    Having reconnect functionality after the beanstalkd server is gone away was also crucial for our infrastructure.

    As we tried to implement a reconnect logic around fivebeans, we ran into multiple issues. One of them was that if we call worker.watch() inside our worker.on('close') callback function, fivebeans would also add the client listeners (on('connect'), on('error'), etc.) again, which of course would lead to an event emitter memory leak during the reconnection attempts.

    Just calling worker.client.connect() during the reconnection attempts fixed the listener issue. However after the beanstalkd server was up again, all new jobs added to the queue had a mysterious hang followed by a DEADLINE_SOON after they were processed. At this point, the handler was already done, but it took a couple of seconds until the job was properly deleted.

    So not sure if a reconnection behavior should be part of fivebeans, but one possible solution could be to write a simple wrapper which uses a separate connection to just check the availability of the beanstalkd server and reinitializes the worker if it was able to reconnect.

    The following seems to work

    const Beanworker = require('fivebeans').worker;
    const Reconnect = require('net-socket-reconnect')
    
    var beanHost = "127.0.0.1";
    var beanPort = 11300;
    
    var beanServer = Reconnect({
        host: beanHost,
        port: beanPort,
        reconnectInterval: 5000
    });
    
    var worker, options = {
        id: 'worker-test-01',
        host: beanHost,
        port: beanPort,
        handlers: {
            test: require('./handler/test')()
        },
        ignoreDefault: true
    }
    
    beanServer.on('connect', function () {
        worker = new Beanworker(options);
        worker.start(['test_tube']);
    });
    
    beanServer.on('close', function () {
        if (worker) {
            worker = null;
            delete worker;
        }
    });

    What do you think?

  8. ceejbot commented on Jun 7, 2016

    @ceejbot
    Owner

    Okay, this is pretty clearly something the module needs to do. Give me a little bit to reacquaint myself with what the heck I was thinking when I wrote it (my first node module ever, if you want to be scared) and make it reconnect. I like the server approach above.

  9. michaelfreund commented on Oct 31, 2016

    @michaelfreund

    @ceejbot did you reacquaint with your first baby? 😁 meanwhile our solution runs in production without any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions