denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.81k stars 493 forks source link

The ReturnMessageQueue/Rowsq implementation needs tweaks to message ordering #720

Closed shueybubbles closed 2 years ago

shueybubbles commented 2 years ago

https://github.com/denisenkom/go-mssqldb/blob/e53873151a46af22b77fa010fc1485c31cbb38b1/messages_example_test.go#L46 The message queue example illustrates that the application waits for the first MsgNext event before calling Rows.Next.

Today, ProcessQueryResponse doesn't post a MsgNext event until the reader encounters column metadata. However, the reader channel only has a 5 token buffer, so if there are 5 tokens in the queue before it reaches any columns, the query blocks. Posting MsgNext right away will nudge the app to read tokens in the channel.

Exposed by a sqlcmd issue https://github.com/microsoft/go-sqlcmd/issues/48

shueybubbles commented 2 years ago

My earlier assertion about MsgNext isn't quite right. We need to send MsgNextResult for every type of doneStruct and MsgNext for every column set. We're also missing handling of ServerError and doneInProcStruct

This fix will also address https://github.com/microsoft/go-sqlcmd/issues/47