Skip to content

Celery worker over SSL #1859

Closed
Closed

Description

@jonathanlabanca

Hi there,

Several days ago I try to configure a celery worker running under SSL with a self-signed certificate. The broker that I using is RabbitMQ and try debugging all configurations without receiving errors in the certificate or in the configuration.

I configuring my worker without ssl and tasks are processed smoothly, but reactivating celery with ssl are not be processed again.

After various tests, a few hours ago can resolve the problem by adding the parameter "- without-mingle" to my startup script.

The line ran in both cases (with SSL and without SSL) was as follows:

/usr/bin/celery worker -A project -B -E -l DEBUG --uid=celery --gid=celery --workdir=/usr/local/celery/ --pidfile=/var/run/celery/%n.pid --logfile=/var/log/celery/%n.log

Currently executed following to operate under SSL:

/usr/bin/celery worker -A project -B -E -l DEBUG --uid=celery --gid=celery --workdir=/usr/local/celery/ --pidfile=/var/run/celery/%n.pid --logfile=/var/log/celery/%n.log --without-mingle

Have any idea that can generate this problem?
Regards.

Activity

  1. ionelmc commented on Feb 8, 2014

    @ionelmc
    Contributor

    This may be a the same buffering issue or something related to #1847 - watch that issue for fixes.

  2. ionelmc commented on Feb 8, 2014

    @ionelmc
    Contributor

    @jonathanlb It appears this is a double stalling issue caused by buffering in pyamqp/amqplib/librabbitmq and the SSL wrappers from the socket module.

    I've fixed (see #1847) pyamqp and amqplib to not buffer the reads (and prevent stalling) but the SSL socket wrapper can still stall (has own internal buffering). See man page for more details about this:

    SSL_read() works based on the SSL/TLS records. The data are received in records (with a maximum record size of 16kB for SSLv3/TLSv1). Only when a record has been completely received, it can be processed (decryption and check of integrity). Therefore data that was not retrieved at the last call of SSL_read() can still be buffered inside the SSL layer and will be retrieved on the next call to SSL_read(). If num is higher than the number of bytes buffered, SSL_read() will return with the bytes buffered. If no more bytes are in the buffer, SSL_read() will trigger the processing of the next record.

    I think best approach here (given current Hub implementation) is to add timers that generate fake Hub readiness events (so that these sockets get unstuck). @ask What do you think ?

  3. ask commented on Feb 10, 2014

    @ask
    Contributor

    @ionelmc, I don't know, that could work I guess, what do other async libs do with SSL?

  4. ionelmc commented on Feb 10, 2014

    @ionelmc
    Contributor

    I believe they don't stall because they optimize away polling (eg: try read first, if EAGAIN, then add in the poller). Examples:

    Now that I think more about it I would think the current amqp protocol has some deficiency in the way it handles readiness - there are very many places that don't try very hard to exhaust the internal buffers and queues:

  5. ask commented on Feb 14, 2014

    @ask
    Contributor

    Right, that would make sense but that does not really apply here when there is no request to read in the first place?

    It would help with synchronous AMQP calls like queue.declare:

    socket.write(create_queue_declare_frame())
    socket.read()  # <- wait for queue_declare_ok frame
    

    But there is no 'wait for 1 message' call here, the broker simply sends new messages
    as they are ready, without participation from the client.

    So when using async I/O the only way to know that there is a new frame to be read
    is when the socket is ready for read, and you cannot wake up to do dummy reads
    at any reasonable interval without creating either a high frequency read loop or latency.

  6. ask commented on Feb 14, 2014

    @ask
    Contributor

    Forgot to say that yeah, I think calling drain_events at intervals of 1 second or so when using SSL would be the only solution (but that would also be the case in twisted, tornado, tulip if they don't have another way to solve it)

  7. ask commented on Jun 23, 2016

    @ask
    Contributor

    Closing this, as we don't have the resources to complete this task.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions