fix 100% cpu usage on linux while using sqs #1189
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix celery/celery#5299
kombu uses cURL
multi_socket
API, which is non-blocking callback-based API. But it doesn't work well in linux, because of epoll weird file descriptor management. When you use epoll, you must always remove FD from epoll before closing FD, but when curl decides that it doesn't need some particular socket, it will close that socket and after that it will inform you that the socket is closed - so you don't have a chance to remove it from epoll in time. See https://curl.haxx.se/libcurl/c/curl_multi_socket_action.html for more info about this API.In our case we periodically query an SQS queue, and curl performs the queries via keep-alive https connection. But sometimes (about once per minute or two) SQS sends a response with
Connection: close
header, then curl closes the socket.I suggest this workaround: before every curl invocation, let's remove from our selector every curl-related file descriptor. And after we get control back from curl, we insert those back (most of the time curl will update socket states, so we should not forget to consider it). So as a result we are going to work with epoll in old-fashioned select/poll way.