ziutek / telnet

Package to handle a telnet connection
Other
141 stars 60 forks source link

SkipUntil leads to "index out of range" error in bufio #19

Closed acham closed 5 years ago

acham commented 5 years ago

We sometimes use SkipUntil with a single string argument in our code, for example teln.SkipUntil("querymvisvc"), and this sometimes leads to the error stack below:

panic: runtime error: index out of range

goroutine 853 [running]:
bufio.(*Reader).ReadByte(0xc0024d57a0, 0x54f837, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:251 +0xcb
github.com/ziutek/telnet.(*Conn).tryReadByte(0xc00175ccc0, 0x560037, 0x0, 0x0)
    /go/pkg/mod/github.com/ziutek/telnet@v0.0.0-20180329124119-c3b780dc415b/conn.go:230 +0x33
github.com/ziutek/telnet.(*Conn).ReadByte(0xc00175ccc0, 0x37, 0x0, 0x0)
    /go/pkg/mod/github.com/ziutek/telnet@v0.0.0-20180329124119-c3b780dc415b/conn.go:261 +0x38
github.com/ziutek/telnet.(*Conn).readUntil(0xc00175ccc0, 0x5aec00, 0xc006c55130, 0x1, 0x1, 0xc002245538, 0x40bff8, 0x10, 0x570320, 0x1, ...)
    /go/pkg/mod/github.com/ziutek/telnet@v0.0.0-20180329124119-c3b780dc415b/conn.go:364 +0x12e
github.com/ziutek/telnet.(*Conn).SkipUntil(0xc00175ccc0, 0xc006c55130, 0x1, 0x1, 0x3, 0x3)
    /go/pkg/mod/github.com/ziutek/telnet@v0.0.0-20180329124119-c3b780dc415b/conn.go:405 +0x51
bitbucket.org/team/teamrepo/processor.queryDMC(0x5e2440, 0xc00175ccc0, 0xc003646223, 0x2, 0xc0002bf640, 0xe, 0xc0002bf638, 0x4, 0xc0002bf650, 0x6, ...)
ziutek commented 5 years ago

Hmm...

bufio.ReadByte shouldn't panic. It looks like a bug in bufio package. Or...

Or you use telnet connection concurrently. Try compile your program with race detector enabled.

acham commented 5 years ago

It was indeed a well-hidden race condition. Thanks.