input and output buffers get out of sync in io streams

Bug #1600610 reported by Guillaume LE VAILLANT
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Triaged
High
Unassigned

Bug Description

(with-open-file (stream "/tmp/foo"
                        :direction :io
                        :if-exists :overwrite
                        :if-does-not-exist :create)
  (write-string "abc" stream)
  (file-position stream 0)
  (write-char #\x stream)
  (read-char stream))
=> #\a

Tags: streams
Stas Boukarev (stassats)
summary: - read-sequence can move file-position beyond end of file
+ input and output buffers get out of sync in io streams
description: updated
Changed in sbcl:
status: New → Triaged
importance: Undecided → High
tags: added: streams
Revision history for this message
Guillaume LE VAILLANT (guillaume-le-vaillant) wrote :

Flushing the output buffer by hand before reading seems to work.

(with-open-file (stream "string.txt"
                        :direction :io
                        :if-exists :overwrite
                        :if-does-not-exist :create)
  (write-string "abc" stream)
  (file-position stream 0)
  (write-char #\d stream)
  (finish-output stream)
  (read-char stream))
=> #\b

Maybe the code for flushing the output buffer before reading in the case of a file stream opened in io mode is missing...

Revision history for this message
Guillaume LE VAILLANT (guillaume-le-vaillant) wrote :

The attached patch seems to fix the issue. It adds calls to finish-fd-stream-output in input-wrapper and input-wrapper/variable-width. However, I'm not familiar with the internals of SBCL, so it might not be the best place to put them...

Revision history for this message
Stas Boukarev (stassats) wrote :

Flushing on each read will kill performance.

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.