Skip to content

Celery worker connection with Rabittmq met broken pipe error IN Gevent Mode #3377

Closed

Description

@jcyrss

Celery version 3.1.22

In our web performance testing, Celery worker connection with Rabbitmq met broken pipe error IN Gevent Mode, while no problem when Celery worker work in Process pool mode.
After that, Celery workers will not get task messages from Rabbitmq anymore until they are restarted.

That issue always happen when the speed of Celery workers consuming task messages slower than Django applications producing messages, and about 3 thounds of messages piled in Rabbitmq.

Is that due to Gevent Monkey Patch?

====== Celery log ======

[2016-08-08 13:52:06,913: CRITICAL/MainProcess] Couldn't ack 293, reason:error(32, 'Broken pipe')
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/kombu/message.py", line 93, in ack_log_error
self.ack()
File "/usr/local/lib/python2.7/site-packages/kombu/message.py", line 88, in ack
self.channel.basic_ack(self.delivery_tag)
File "/usr/local/lib/python2.7/site-packages/amqp/channel.py", line 1584, in basic_ack
self._send_method((60, 80), args)
File "/usr/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 56, in _send_method
self.channel_id, method_sig, args, content,
File "/usr/local/lib/python2.7/site-packages/amqp/method_framing.py", line 221, in write_method
write_frame(1, channel, payload)
File "/usr/local/lib/python2.7/site-packages/amqp/transport.py", line 182, in write_frame
frame_type, channel, size, payload, 0xce,
File "/usr/local/lib/python2.7/site-packages/gevent/_socket2.py", line 412, in sendall
timeleft = self.__send_chunk(chunk, flags, timeleft, end)
File "/usr/local/lib/python2.7/site-packages/gevent/_socket2.py", line 351, in __send_chunk
data_sent += self.send(chunk, flags)
File "/usr/local/lib/python2.7/site-packages/gevent/_socket2.py", line 320, in send
return sock.send(data, flags)
error: [Errno 32] Broken pipe

======= Rabbitmq log ==================

=ERROR REPORT==== 8-Aug-2016::14:28:33 ===
closing AMQP connection <0.15928.4> (10.26.39.183:60732 -> 10.26.39.183:5672):
{writer,send_failed,{error,enotconn}}

=ERROR REPORT==== 8-Aug-2016::14:29:03 ===
closing AMQP connection <0.15981.4> (10.26.39.183:60736 -> 10.26.39.183:5672):
{writer,send_failed,{error,enotconn}}

=ERROR REPORT==== 8-Aug-2016::14:29:03 ===
closing AMQP connection <0.15955.4> (10.26.39.183:60734 -> 10.26.39.183:5672):
{writer,send_failed,{error,enotconn}}

Activity

  1. ask commented on Aug 9, 2016

    @ask
    Contributor

    This is probably fixed in master

  2. jcyrss commented on Aug 10, 2016

    @jcyrss
    Author

    I tried with 4.x RC and met some issues

    when I conduct load test, new issue appears as the following log shows.

    [2016-08-10 13:15:55,590: CRITICAL/MainProcess] Couldn't ack 141, reason:error(104, 'Connection reset by peer')
    Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/kombu/message.py", line 101, in ack_log_error
    self.ack(multiple=multiple)
    File "/usr/local/lib/python2.7/site-packages/kombu/message.py", line 96, in ack
    self.channel.basic_ack(self.delivery_tag, multiple=multiple)
    File "/usr/local/lib/python2.7/site-packages/amqp/channel.py", line 1425, in basic_ack
    spec.Basic.Ack, argsig, (delivery_tag, multiple),
    File "/usr/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 62, in send_method
    conn.frame_writer.send((1, self.channel_id, sig, args, content))
    File "/usr/local/lib/python2.7/site-packages/amqp/method_framing.py", line 165, in frame_writer
    write(view[:offset])
    File "/usr/local/lib/python2.7/site-packages/amqp/transport.py", line 253, in write
    self._write(s)
    File "/usr/local/lib/python2.7/site-packages/gevent/_socket2.py", line 412, in sendall
    timeleft = self.__send_chunk(chunk, flags, timeleft, end)
    File "/usr/local/lib/python2.7/site-packages/gevent/_socket2.py", line 351, in __send_chunk
    data_sent += self.send(chunk, flags)
    File "/usr/local/lib/python2.7/site-packages/gevent/_socket2.py", line 320, in send
    return sock.send(data, flags)
    error: [Errno 104] Connection reset by peer
    [2016-08-10 13:15:55,592: CRITICAL/MainProcess] Couldn't ack 140, reason:RecoverableConnectionError(None, u'connection already closed', None, u'')
    Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/kombu/message.py", line 101, in ack_log_error
    self.ack(multiple=multiple)
    File "/usr/local/lib/python2.7/site-packages/kombu/message.py", line 96, in ack
    self.channel.basic_ack(self.delivery_tag, multiple=multiple)
    File "/usr/local/lib/python2.7/site-packages/amqp/channel.py", line 1425, in basic_ack
    spec.Basic.Ack, argsig, (delivery_tag, multiple),
    File "/usr/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 64, in send_method
    raise RecoverableConnectionError('connection already closed')

    [2016-08-10 13:12:39,072: CRITICAL/MainProcess] beat raised exception <type 'exceptions.TypeError'>: TypeError('String or Integer object expected for key, unicode found',)
    Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/celery/apps/beat.py", line 111, in start_scheduler
    service.start()
    File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 520, in start
    humanize_seconds(self.scheduler.max_interval))
    File "/usr/local/lib/python2.7/site-packages/kombu/utils/init.py", line 302, in get
    value = obj.dict[self.name] = self.*get(obj)
    File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 561, in scheduler
    return self.get_scheduler()
    File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 556, in get_scheduler
    lazy=lazy)
    File "/usr/local/lib/python2.7/site-packages/celery/utils/imports.py", line 60, in instantiate
    return symbol_by_name(name)(_args, _kwargs)
    File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 408, in __init

    Scheduler.init(self, _args, *_kwargs)
    File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 208, in init
    self.setup_schedule()
    File "/usr/local/lib/python2.7/site-packages/celery/beat.py", line 438, in setup_schedule
    self._store['entries']
    File "/usr/local/lib/python2.7/shelve.py", line 121, in getitem
    f = StringIO(self.dict[key])
    File "/usr/local/lib/python2.7/bsddb/init.py", line 270, in getitem
    return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
    File "/usr/local/lib/python2.7/bsddb/dbutils.py", line 68, in DeadlockWrap
    return function(__args, *__kwargs)
    File "/usr/local/lib/python2.7/bsddb/init.py", line 270, in
    return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
    TypeError: String or Integer object expected for key, unicode found
    celery beat v4.0.0rc3 (0today8) is starting.

    • Issue yadayada depends on python-cjson #3
      I can't belive it will make rabbitmq web manage page of queue raise exception.
      But that seem really cause by installing Celery 4RC, if I reinstall Celery 3.x, that page works again.

    The following is what it complains in web manage page of Rabbitmq.

    Got response code 500 with body {"error":"Internal Server Error","reason":"{error,{exit,{ucs,{bad_utf8_character_code}},\n [{xmerl_ucs,from_utf8,1,[{file,"xmerl_ucs.erl"},{line,186}]},\n {mochijson2,json_encode_string,2,\n [{file,"src/mochijson2.erl"},{line,218}]},\n {mochijson2,'-json_encode_proplist/2-fun-0-',3,\n [{file,"src/mochijson2.erl"},{line,198}]},\n {lists,foldl,3,[{file,"lists.erl"},{line,1262}]},\n {mochijson2,json_encode_proplist,2,\n [{file,"src/mochijson2.erl"},{line,202}]},\n {mochijson2,'-json_encode_proplist/2-fun-0-',3,\n [{file,"src/mochijson2.erl"},{line,199}]},\n {lists,foldl,3,[{file,"lists.erl"},{line,1262}]},\n {mochijson2,json_encode_proplist,2,\n [{file,"src/mochijson2.erl"},{line,202}]}]}}\n"}

  3. jcyrss commented on Aug 12, 2016

    @jcyrss
    Author

    Hi, maybe I found one clue to reproduce that.
    That issue alway happen when the speed of Celery workers consuming task messages slower than Django applications producing messages, and about 3 thounds of messages piled in Rabbitmq.

  4. qinshuang commented on Aug 22, 2016

    @qinshuang

    I met the same problem, Is it fixed?

  5. jamestrose2 commented on Oct 25, 2016

    @jamestrose2

    I am also seeing this issue with the most recent build, and I think it might have something to do with Django and exception handling. Has anyone developed a solution or workaround?

  6. robsonpeixoto commented on Dec 3, 2016

    @robsonpeixoto

    I'm having a similar bug with celery 4.0.0 #3649

  7. alanhamlett commented on Jan 9, 2017

    @alanhamlett
  8. nhaas-twist commented on Mar 2, 2017

    @nhaas-twist

    Same. Was fine under Celery 3.x. Broken pipe under 4.0.2.

  9. leobuskin commented on Aug 22, 2017

    @leobuskin

    Can confirm @jcyrss - same, when Django produces messages faster than Celery workers consuming, not sure is it gevent monkey patch or not, but now trying to find a solution, first step - multiplying celery instances

  10. vesterbaek commented on Oct 9, 2017

    @vesterbaek

    Also seeing this with 4.1.0 and rabbitmq

  11. hoozecn commented on Oct 25, 2017

    @hoozecn

    Having the same prob with celery 4.0.2 + gevent + python3

  12. listingmirror commented on Nov 1, 2017

    @listingmirror

    I see this in prefork under high load

  13. canassa commented on Nov 1, 2017

    @canassa

    This issue happens if the machine is starving for resources, what probably happens is that the internal state machine of gevent gets too busy and the events get too delayed therefore causing all kinds of issues, broken pipes, closed sockets, etc.

    I had this issue for several weeks and I tried all sorts of workarounds for it (including replacing gevent, upgrading Celery from 3 to 4, etc), and what ultimately fixed the problem was upgrading the EC2 instance too a much bigger one and keeping a close on it to make that the load is never 100% for too long. I have never had any problems since then.

    I don't think this is a issue with Celery per se so I would suggest the maintainers of Celery to close this issue and others similar to this. But adding some documentation about this on a best practices page would be a nice add-on to the project.

  14. listingmirror commented on Nov 1, 2017

    @listingmirror

    @canassa what is starved for resources here?

    I have my rabbitmq box in kubernetes on a very very very big machine. I limit it to 8GB of ram, and no CPU limit. Memory usage sits at maybe 2 GB. Anything in specific I should be looking for?

  15. 33 remaining items

  16. madchap commented on May 28, 2020

    @madchap

    Still happening in 4.4.2 apparently. I am hit by this.

  17. auvipy commented on May 28, 2020

    @auvipy
    Member

    feel free to test and update the unit test for the linked patch

  18. Honst211 commented on Nov 28, 2020

    @Honst211

    This problem still exists in 4.4.7

  19. alex-milanovic commented on Dec 21, 2020

    @alex-milanovic

    Getting this in 5.0.2. Seems to be failing outside my @app.task so can't use a try statement to catch it

    [2020-12-21 02:51:47,706: CRITICAL/MainProcess] Couldn't ack 84, reason:BrokenPipeError(32, 'Broken pipe')
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.7/site-packages/kombu/message.py", line 128, in ack_log_error
        self.ack(multiple=multiple)
      File "/opt/conda/lib/python3.7/site-packages/kombu/message.py", line 123, in ack
        self.channel.basic_ack(self.delivery_tag, multiple=multiple)
      File "/opt/conda/lib/python3.7/site-packages/amqp/channel.py", line 1392, in basic_ack
        spec.Basic.Ack, argsig, (delivery_tag, multiple),
      File "/opt/conda/lib/python3.7/site-packages/amqp/abstract_channel.py", line 57, in send_method
        conn.frame_writer(1, self.channel_id, sig, args, content)
      File "/opt/conda/lib/python3.7/site-packages/amqp/method_framing.py", line 183, in write_frame
        write(view[:offset])
      File "/opt/conda/lib/python3.7/site-packages/amqp/transport.py", line 321, in write
        self._write(s)
      File "/opt/conda/lib/python3.7/site-packages/gevent/_socket3.py", line 534, in sendall
        return _socketcommon._sendall(self, data_memory, flags)
      File "/opt/conda/lib/python3.7/site-packages/gevent/_socketcommon.py", line 392, in _sendall
        timeleft = __send_chunk(socket, chunk, flags, timeleft, end)
      File "/opt/conda/lib/python3.7/site-packages/gevent/_socketcommon.py", line 321, in __send_chunk
        data_sent += socket.send(chunk, flags)
      File "/opt/conda/lib/python3.7/site-packages/gevent/_socket3.py", line 515, in send
        return self._sock.send(data, flags)
    BrokenPipeError: [Errno 32] Broken pipe
    
  20. removed their assignment
    on Dec 22, 2020
  21. modified the milestones: 4.4.x, 5.1.0 on Dec 22, 2020
  22. modified the milestones: 5.1.0, 5.2 on Mar 28, 2021
  23. ozgurakcali commented on Jul 29, 2021

    @ozgurakcali

    I've also been getting these errors with celery / rabbitmq / gevent workers. I've increased the resources on the server, so that max cpu usage hits at most around 50%, but still got these errors. Tried different concurrency levels between 4 and 128 with no help.

    celery==5.1.2
    gevent==21.1.2
    amqp ==5.0.6
    rabbitmq: AWS managed service

    Also, this does not happen with our dev environment, tasks there run on a much smaller db, so issuing much less db queries and external requests, I imagine this issue might have something to do with task loads.

    We decided not to use gevent workers, but switched to threads workers, still enabling us more concurrency at less resource usage when compared to prefork workers, at the expense of possible less efficiency of os task scheduler when compared to gevent event loop.

  24. idanmantin commented on Oct 8, 2021

    @idanmantin

    Having the same issue:

    Couldn’t ack 1588, reason:BrokenPipeError(32, 'Broken pipe ') …

    Running supervisord, celery==4.3.0 with gevent workers.
    gevent==1.4.0
    amqp==2.5.0
    kombu==4.6.3

    The worker is stuck, although supervisord is configured with autorestart=true and should take care of restarting.

    Reason:
    kombu not handling BrokenPipeError, that was fixed in version: v5.2.0rc1

    This solved the problem:
    https://github.com/celery/kombu/blob/0253cfb7b2379b2a4290ee663d40f55c03147f99/kombu/message.py#L129-L132

  25. auvipy commented on Oct 8, 2021

    @auvipy
    Member

    you should upgrade to celery 5.2.0rc1 for that.

  26. vladjkeeee13 commented on Mar 30, 2023

    @vladjkeeee13

    Got the same error.
    Try to increase memory for this worker. It helped in my case.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions