[FIXED] Issues with std::io::Lines: read blocks forever


#1

I’ve got an issue with std::io::Lines iterator in my project — rust-mpd.
I have two users complaining about the issue, and I’m out of ideas:

My problem is the following: my mpd is a pure-Rust client library for MPD. MPD protocol is really simple: you open socket and then write commands to it, and read result, linewise, until you meet “OK\n” string, which means “end of reply”. Protocol is line oriented: one command per line, one reply unit per line. So I use ReadBuf::lines() method to get std::io::Lines iterator, and then read lines and parse them one by one, nothing fancy.

But once in a while Lines::next() reads whole reply from MPD into its internal buffer and then issues another read() request, which blocks and never returns, just because MPD already sent everything it wanted to send. So from end user perspective, they request current song info, and the method never returns (well, until connection times out, in which case they get an error).

I tried to debug it with strace and reproduce the bug locally on my laptop, and with my local MPD server, but to no avail. The bug is reproducible for least two users with different setups: one with remote MPD server, but only for this single setup (he tried other variants, like local server etc, but bug wasn’t reproduced), and the second user tells he has this bug reproduced with local MPD server. They both both tried to work with MPD via netcat, and it all worked like a charm, the bug is somewhere on rust-mpd side. They also provided network and strace dumps, analyzing which I came to the conclusions I described above.

I’m out of ideas, and ask for help here. I’ll try to provide any info you ask me for.

Thank you in advance.


#2

The Lines iterator calls into BufRead::read_line which calls into BufRead::read_until so if there was a bug that resulted in an extra call after a \n was already received, read_until would be the place to look.


#3

Yes, I already found it all out, sorry for not being specific enough, I just summed up everything happening in libstd under “in std::io::Lines” umbrella. I looked at read_until, but I couldn’t find anything suspicious enough, that would explain my bug. Maybe my eye is too tired, so I just need a fresh eye here. Thanks for pointers and attention, anyway.


#4

Doh, it was an old error in my mpd library, specifically in published version 0.0.7.
And it was long fixed in master branch, which I was testing, no wonder I could not reproduce the bug.
The bug is fixed by just publishing fresh version 0.0.8.
Sorry for being so unobservant, seems like I need some rest.