Issue1154

classification
Title: socket.settimeout not working for recv
Type: behaviour Severity: major
Components: Library Versions: 2.2.2
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amak Nosy List: amak, frt
Priority: high Keywords:

Created on 2008-10-16.07:58:38 by frt, last changed 2008-12-21.22:32:01 by amak.

Messages
msg3688 (view) Author: Fredrik Rothamel (frt) Date: 2008-10-16.07:58:37
Setting timeout on a socket does not work.

Sample code:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(3)
    s.connect((HOST, PORT))
    data = s.recv(8)

Using Jython 2.2.1 on java1.6.0_07, the recv call blocks indefinitely.
msg3689 (view) Author: Alan Kennedy (amak) Date: 2008-10-17.17:29:50
This is indeed a bug.

The cause is the use of nio.channels.SocketChannel.read methods, which
are unaffected by net.Socket.setSoTimeout values.

As with connect timeouts, I will have to special case the read to use
the java.net methods when in timeout mode, and the java.nio methods
otherwise.

I will fix this tomorrow.
msg3691 (view) Author: Alan Kennedy (amak) Date: 2008-10-19.11:12:21
This is now fixed in the 2.2 branch.

Jython 2.2.1 on java1.4.2_17
Type "copyright", "credits" or "license" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect( ('localhost', 80) )
>>> s.settimeout(3)
>>> s.recv(8)
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "C:\jython\release_22_maint\jython\dist\Lib\socket.py", line 789,
in recv
timeout: timed out

If you want to get the updated module, you can wait until a 2.2.2
release, or you can download it from SVN

https://jython.svn.sourceforge.net/svnroot/jython/branches/Release_2_2maint/jython/Lib/socket.py

I will mark this bug report as fixed when the bug is also fixed on
trunk, which will be in a few days, after some multiple platform testing.

Also modified the bug description to be more precise.
msg3973 (view) Author: Alan Kennedy (amak) Date: 2008-12-21.22:32:00
Fix checked into trunk at r5783.
History
Date User Action Args
2008-12-21 22:32:01amaksetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg3973
2008-10-19 11:12:22amaksettitle: socket.settimeout not working -> socket.settimeout not working for recv
messages: + msg3691
versions: + 2.2.2, - 2.2.1rc1
2008-10-17 17:29:51amaksetpriority: high
assignee: amak
resolution: accepted
messages: + msg3689
nosy: + amak
2008-10-16 07:58:38frtcreate