twisted / twisted/twisted

Serialport connection lost not handled.

Open
#4,249 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug core new priority-normal
Dominant language
Python
Stars
6k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
10

Description

mdamen's avatar mdamen reported
Trac ID trac#4249
Type defect
Created 2010-01-30 19:49:22Z

When you disconnect a device connected to the serial port, twisted reports an unhandled error. Here is the traceback:

Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\twisted\python\log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "C:\Python26\Lib\site-packages\twisted\python\log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "C:\Python26\Lib\site-packages\twisted\python\context.py", line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "C:\Python26\Lib\site-packages\twisted\python\context.py", line 37, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "C:\Python26\Lib\site-packages\twisted\internet\win32eventreactor.py", line 211, in _runAction
    closed = getattr(fd, action)()
  File "C:\Python26\Lib\site-packages\twisted\internet\_win32serialport.py", line 68, in serialReadEvent
    n = win32file.GetOverlappedResult(self._serial.hComPort, self._overlappedRead, 0)
pywintypes.error: (995, 'GetOverlappedResult', 'The I/O operation has been aborted because of either a thread exit or an application request.')

There should be some kind of error handling to prevent this, I had a look at it but can't figure out what should be done. Here's a basic example to reproduce the problem:

from twisted.internet import protocol
from twisted.internet.serialport import SerialPort
from sys import platform
if platform == 'win32':
    from twisted.internet import win32eventreactor
    win32eventreactor.install()
from twisted.internet import reactor

class TestProto(protocol.Protocol):
    def connectionMade(self):
        print "connection made"
        
    def connectionLost(self):
        print "connection lost"

SerialPort(TestProto(),2, reactor, '115200')        
reactor.run()
Searchable metadata
trac-id__4249 4249
type__defect defect
reporter__mdamen mdamen
priority__normal normal
milestone__ 
branch__ 
branch_author__itamar itamar
status__new new
resolution__None None
component__core core
keywords__ 
time__1264880962000000 1264880962000000
changetime__1321500170000000 1321500170000000
version__None None
owner__ 
cc__detly

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in twisted/internet/_win32serialport.py at serialReadEvent and review the call path from win32eventreactor.py. Reproduce the Windows serial-port disconnect with the example, then verify that the aborted I/O is handled without an unhandled traceback and that the connection-loss behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.