This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: file_wrapper fails to provide getsockopt()
Type: behavior Stage: commit review
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, georg.brandl, giampaolo.rodola, josiahcarlson, lukasz.langa
Priority: normal Keywords: patch

Created on 2010-07-23 14:33 by lukasz.langa, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9354.diff lukasz.langa, 2010-07-27 22:32 Patch introducing getsockopt() for asyncore.file_wrapper + unit tests
Messages (5)
msg111333 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2010-07-23 14:33
Tested on Python 3.2a0 on Mac OS 10.6.4.

When you specify the most basic `file_dispatcher` and run the loop, `file_wrapper` fails because it doesn't provide the `getsockopt()` to fake being a socket.

The code
--------

import asyncore
import os

class FileDispatcher(asyncore.file_dispatcher):
    def handle_read(self):
        data = self.recv(8192)

fd = os.open('/etc/passwd', os.O_RDONLY)
s = FileDispatcher(fd)
os.close(fd)
asyncore.loop(timeout=0.01, use_poll=True, count=2)

Expected result
---------------
None, it should run OK silently.

Actual result
-------------
error: uncaptured python exception, closing channel <__main__.FileDispatcher at 0x100524e10> (<class 'AttributeError'>:'file_wrapper' object has no attribute 'getsockopt' [/opt/error-report/py3k/Lib/asyncore.py|readwrite|106] [/opt/error-report/py3k/Lib/asyncore.py|handle_write_event|449])
Traceback (most recent call last):
  File "/opt/error-report/py3k/Lib/asyncore.py", line 106, in readwrite
    obj.handle_write_event()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 449, in handle_write_event
    err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
AttributeError: 'file_wrapper' object has no attribute 'getsockopt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/error-report/error_report.py", line 11, in <module>
    asyncore.loop(timeout=0.01, use_poll=True, count=2)
  File "/opt/error-report/py3k/Lib/asyncore.py", line 214, in loop
    poll_fun(timeout, map)
  File "/opt/error-report/py3k/Lib/asyncore.py", line 195, in poll2
    readwrite(obj, flags)
  File "/opt/error-report/py3k/Lib/asyncore.py", line 119, in readwrite
    obj.handle_error()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 489, in handle_error
    self.handle_close()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 508, in handle_close
    self.close()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 396, in close
    self.socket.close()
  File "/opt/error-report/py3k/Lib/asyncore.py", line 617, in close
    os.close(self.fd)
OSError: [Errno 9] Bad file descriptor

Patch
-----
Please find attached a patch that does add a unit test for this specific case and adds the most simple `getsockopt()` possible that is still reasonable. The patch was made with trunk r83090.
msg111336 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2010-07-23 14:35
Here goes the patch.
msg111741 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2010-07-27 22:32
Patch updated to conform with the new test layout by Ezio Melotti. Implementation now also doesn't use assertions but regular exceptions.
msg111742 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-07-27 22:35
Looks good to me.
msg111774 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-28 08:21
Applied in r83201. Thanks!
History
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53600
2010-07-28 08:21:02georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg111774

resolution: fixed
2010-07-27 22:35:40eric.araujosetnosy: + eric.araujo

messages: + msg111742
stage: commit review
2010-07-27 22:32:18lukasz.langasetfiles: + issue9354.diff

messages: + msg111741
2010-07-27 22:29:44lukasz.langasetfiles: - issue9354.diff
2010-07-23 14:47:38lukasz.langasettitle: fire_wrapper fails to provide getsockopt() -> file_wrapper fails to provide getsockopt()
2010-07-23 14:35:48lukasz.langasetfiles: + issue9354.diff
keywords: + patch
messages: + msg111336
2010-07-23 14:33:26lukasz.langacreate