READ-CHAR-NO-HANG hangs on SB-SYS:WAIT-UNTIL-FD-USABLE

Bug #1794089 reported by Michał "phoe" Herda
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Invalid
Undecided
Unassigned

Bug Description

READ-CHAR-NO-HANGS hung on me with 100% CPU usage after I tried to read from a freshly closed socket.
This socket was freshly closed though, so I suspect some kind of race condition.
If I read the docstrings at https://github.com/sbcl/sbcl/blob/e98378ca004ef6d101b384f6c3130f24b7a1bc1f/src/code/serve-event.lisp#L215 correctly, then the call (SB-SYS:WAIT-UNTIL-FD-USABLE 7 :INPUT NIL NIL) has no timeout (will hang indefinitely). I don't think that's the correct behavior in case of READ-CHAR-NO-HANG that shouldn't hang at all.

I'm on SBCL 1.4.9.

-------------------------------------

Interrupt from Emacs
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [CONTINUE] Continue from break.
 1: [RETRY] Retry SLIME REPL evaluation request.
 2: [*ABORT] Return to SLIME's top level.
 3: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1002EC83E3}>)

Backtrace:
  0: ("bogus stack frame")
      [No Locals]
  1: (SB-SYS:WAIT-UNTIL-FD-USABLE 7 :INPUT NIL NIL)
      Locals:
        SB-IMPL::DIRECTION = :INPUT
        SB-IMPL::FD = 7
        SB-IMPL::SERVE-EVENTS = NIL
        SB-IMPL::SIGNALP = NIL
        SB-IMPL::STOP-SEC = NIL
        SB-IMPL::STOP-USEC = NIL
        TIMEOUT = NIL
        SB-IMPL::TO-SEC = NIL
        SB-IMPL::TO-USEC = NIL
  2: (SB-IMPL::REFILL-INPUT-BUFFER #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}>)
      Locals:
        COUNT = 0
        ERRNO = 0
        FD = 7
        STREAM = #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}>
  3: (SB-IMPL::INPUT-CHAR/UTF-8 #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}> T NIL)
      Locals:
        DECODE-BREAK-REASON = NIL
        EOF-ERROR = T
        EOF-VALUE = NIL
        IBUF = #S(SB-IMPL::BUFFER :SAP #.(SB-SYS:INT-SAP #X7F32EA374000) :LENGTH 4096 :HEAD 0 :TAIL 0)
        SIZE = NIL
        STREAM = #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}>
      Catch-tags:
        SB-IMPL::EOF-INPUT-CATCHER
  4: (READ-CHAR-NO-HANG #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}> T NIL #<unused argument>)
      Locals:
        SB-IMPL::%FRC-INDEX% = 512
        SB-IMPL::%FRC-STREAM% = #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}>
        SB-IMPL::EOF-ERROR-P = T
        SB-IMPL::EOF-VALUE = NIL
        STREAM = #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}>
  5: (PEEK-CHAR-NO-HANG #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}> T NIL NIL)
      Locals:
        EOF-ERROR-P = T
        EOF-VALUE = NIL
        INPUT-STREAM = #<SB-SYS:FD-STREAM for "socket 127.0.0.1:44262, peer: 127.0.0.1:38347" {1007E3F583}>
        RECURSIVE-P = NIL
  ...

Revision history for this message
Michał "phoe" Herda (phoe-krk) wrote :

When I compile a function in slime (via C-c C-c), the loop is broken and the execution continues. I assume this is because SBCL serves some other events and then it discovers that the FD is (un)usable and it is capable of proceeding with computation.

Revision history for this message
Michał "phoe" Herda (phoe-krk) wrote :

I was attempting to read from the same socket in two different threads which caused READ-CHAR-NO-HANG to hang nonetheless. This fixed the issue.

Changed in sbcl:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.