Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected EPROTOTYPE returned by sendto on MAC OSX #77631

Open
racitup mannequin opened this issue May 9, 2018 · 6 comments
Open

unexpected EPROTOTYPE returned by sendto on MAC OSX #77631

racitup mannequin opened this issue May 9, 2018 · 6 comments
Assignees
Labels
OS-mac topic-IO type-bug An unexpected behavior, bug, or error

Comments

@racitup
Copy link
Mannequin

racitup mannequin commented May 9, 2018

BPO 33450
Nosy @ronaldoussoren, @ned-deily, @asvetlov, @1st1, @racitup, @erlend-aasland

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/ronaldoussoren'
closed_at = None
created_at = <Date 2018-05-09.19:04:59.565>
labels = ['OS-mac', 'type-bug', 'expert-IO', 'expert-asyncio']
title = 'unexpected EPROTOTYPE returned by sendto on MAC OSX'
updated_at = <Date 2021-06-24.12:30:33.219>
user = 'https://github.com/racitup'

bugs.python.org fields:

activity = <Date 2021-06-24.12:30:33.219>
actor = 'erlendaasland'
assignee = 'ronaldoussoren'
closed = False
closed_date = None
closer = None
components = ['macOS', 'IO', 'asyncio']
creation = <Date 2018-05-09.19:04:59.565>
creator = 'racitup'
dependencies = []
files = []
hgrepos = []
issue_num = 33450
keywords = []
message_count = 4.0
messages = ['316328', '316353', '327724', '396486']
nosy_count = 8.0
nosy_names = ['ronaldoussoren', 'ned.deily', 'asvetlov', 'yselivanov', 'racitup', 'Eamonn Nugent', 'erlendaasland', 'Daniel King']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue33450'
versions = ['Python 3.5', 'Python 3.6']

@racitup
Copy link
Mannequin Author

racitup mannequin commented May 9, 2018

The following exception is raised unexpectedly on macOS versions 10.13, 10.12 & 10.11 at least. It appears to be macOS specific (works okay on Linux).

Further information can be found at the following links:
benoitc/gunicorn#1487
http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/

[2017-03-20 00:46:39 +0100] [79068] [ERROR] Socket error processing request.
Traceback (most recent call last):
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/workers/async.py", line 66, in handle
    six.reraise(*sys.exc_info())
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/six.py", line 625, in reraise
    raise value
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/workers/async.py", line 56, in handle
    self.handle_request(listener_name, req, client, addr)
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/workers/ggevent.py", line 152, in handle_request
    super(GeventWorker, self).handle_request(*args)
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/workers/async.py", line 129, in handle_request
    six.reraise(*sys.exc_info())
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/six.py", line 625, in reraise
    raise value
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/workers/async.py", line 115, in handle_request
    resp.write(item)
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/http/wsgi.py", line 362, in write
    util.write(self.sock, arg, self.chunked)
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gunicorn-19.7.0-py3.6.egg/gunicorn/util.py", line 321, in write
    sock.sendall(data)
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gevent-1.2.1-py3.6-macosx-10.12-x86_64.egg/gevent/_socket3.py", line 418, in sendall
    data_sent += self.send(data_memory[data_sent:], flags)
  File "/Users/ahmad/Projects/Side-Gigs/sa7beh-app/venv/lib/python3.6/site-packages/gevent-1.2.1-py3.6-macosx-10.12-x86_64.egg/gevent/_socket3.py", line 391, in send
    return _socket.socket.send(self._sock, data, flags)
OSError: [Errno 41] Protocol wrong type for socket

@racitup racitup mannequin added OS-mac topic-IO type-bug An unexpected behavior, bug, or error labels May 9, 2018
@ronaldoussoren
Copy link
Contributor

The second link contains an explanation of what's going on, and that this is unexpected behaviour of the macOS kernel.

I'm not sure what we could do about this, the blog post explains that this error can happen when send(2) is called while the socket is teared down. A possible workaround (based on reading the blog post and without fully analysing the side effects) is to treat EPROTOTYPE the same as EGAIN in the python wrappers for send/write/sendto.

That's easier said than done though, socketmodule.c indirectly calls socket functions through a helper function that does some bookkeeping (including handling EGAIN) and is used for more than just the send calls.

@EamonnNugent
Copy link
Mannequin

EamonnNugent mannequin commented Oct 15, 2018

Fwiw, this also happens in asyncio. Theoretically, I *think* you could wrap a try-except as a monkey patch.

My stack trace is:

Fatal write error on socket transport
protocol: <RequestHandler connected>
transport: <_SelectorSocketTransport fd=163 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 761, in write
    n = self._sock.send(data)
OSError: [Errno 41] Protocol wrong type for socket

I can try to PR the fix mentioned by @ronaldoussoren, though it might take me a bit. I'm happy to do whatever to get this fixed, though, since it's flooding my terminal with several hundred errors every time it happens...

@erlend-aasland
Copy link
Contributor

erlend-aasland commented Jun 24, 2021

See also gh-88395 (bpo-44229).

@kumaraditya303
Copy link
Contributor

Removing "expert-asyncio" as it is a macOS kernel bug and not related to asyncio.

@gvanrossum
Copy link
Member

If we decide to fix this with a workaround, remember to ensure that the workaround also works for asyncio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac topic-IO type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

5 participants