about summary refs log tree commit diff stats
path: root/src/buffer
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-15 12:11:06 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-15 14:48:45 +0100
commit6ed3f5857c2e29396027b1f64b402eaf7ecdace5 (patch)
tree919cdadafcbcf795f17a3ecd9030a7885fd546b6 /src/buffer
parent15e6a2318c35adb7b8b0abe1b5827398068b2c52 (diff)
downloadchawan-6ed3f5857c2e29396027b1f64b402eaf7ecdace5.tar.gz
Fix error handling on buffer close
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/buffer.nim32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index 50269b4b..59655bed 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -1146,8 +1146,11 @@ proc runBuffer(buffer: Buffer, rfd: int) =
     while buffer.alive:
       let events = buffer.selector.select(-1)
       for event in events:
-        if Read in event.events:
-          if event.fd == rfd:
+        if event.fd == rfd:
+          if Error in event.events:
+            # Connection reset by peer, probably. Close the buffer.
+            break loop
+          elif Read in event.events:
             try:
               buffer.readCommand()
             except EOFError:
@@ -1155,24 +1158,25 @@ proc runBuffer(buffer: Buffer, rfd: int) =
               #       getCurrentExceptionMsg() & "\n",
               #       getStackTrace(getCurrentException())
               break loop
-          elif event.fd == buffer.fd:
-            buffer.onload()
           else:
             assert false
-        if Event.Timer in event.events:
-          buffer.selector.unregister(event.fd)
-          var timeout: proc()
-          if buffer.timeouts.pop(event.fd, timeout):
-            timeout()
+        elif event.fd == buffer.fd:
+          if Read in event.events or Error in event.events:
+            buffer.onload()
           else:
             assert false
-        if Error in event.events:
-          if event.fd == rfd:
-            break loop
-          elif event.fd == buffer.fd:
-            buffer.finishLoad()
+        elif event.fd in buffer.timeouts:
+          if Event.Timer in event.events:
+            buffer.selector.unregister(event.fd)
+            var timeout: proc()
+            if buffer.timeouts.pop(event.fd, timeout):
+              timeout()
+            else:
+              assert false
           else:
             assert false
+        else:
+          assert false
   buffer.pstream.close()
   buffer.loader.quit()
   quit(0)