Skip to content

Fix deadlock when the stream Read starts to respond with 'stream not present'.#7

Open
sgielen wants to merge 1 commit intodslipak:masterfrom
sgielen:fix/deadlock-on-stream-not-present
Open

Fix deadlock when the stream Read starts to respond with 'stream not present'.#7
sgielen wants to merge 1 commit intodslipak:masterfrom
sgielen:fix/deadlock-on-stream-not-present

Conversation

@sgielen
Copy link

@sgielen sgielen commented Nov 10, 2025

readToken() would never return. If c is a space character, and b.eof is
false, it would forever call b.readByte which would then call reload(),
ignore the error it returned, not set b.eof, and return a newline which is
still a space character.

Now, if the stream Read returns 'stream not present', reload() would set b.eof,
stopping the deadlock.

…present'.

readToken() would never return. If `c` is a space character, and b.eof is
false, it would forever call `b.readByte` which would then call reload(),
ignore the error it returned, not set b.eof, and return a newline which is
still a space character.

Now, if the stream Read returns 'stream not present', reload() would set b.eof,
stopping the deadlock.
@sgielen
Copy link
Author

sgielen commented Nov 10, 2025

I haven't checked why stream Read starts to respond with 'stream not present' - potentially, at that point eof should also be set? that would make this fix unnecessary

I believe the root cause here is that reload may fail and readByte ignores this, and the caller of readByte can enter in an infinite loop because of this. Perhaps there should be, next to b.eof, also b.err and if readByte sets b.err all reading should stop. That, or readByte should return an err and all callers should check this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant