This is a short post to document an issue we ran into at work so it will show up in search results for people who have this problem in the future.

tl;dr:

  • Use FreeTDS 1.0 if you can.
  • If you're stuck on FreeTDS 0.91 (and possible other pre-1.0 versions), don't use any TDS version above 7.0.

The problem

We were using FreeTDS 0.91, set to use protocol version TDS 7.1, and running our tests in a loop gave results like:

.............................
Ran: 29 tests in: 0.01 seconds.
OK
.........E.........E.........
==============================================================================
Error: MSSQL:19:test_round_trip INT

Error(COMM, "Unexpected EOF from the server")
------------------------------------------------------------------------------
==============================================================================
Error: MSSQL:9:test param out of range

Error(COMM, "Unexpected EOF from the server")
------------------------------------------------------------------------------
Ran: 29 tests in: 0.01 seconds.
FAILED: Cases: 29 Tried: 29 Errors: 2 Failures: 0 Skip:  0 Todo: 0 Timeouts: 0.
.............................
Ran: 29 tests in: 0.05 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
............E.....E..........
==============================================================================
Error: MSSQL:18:test_round_trip INT

Error(COMM, "Unexpected EOF from the server")
------------------------------------------------------------------------------
==============================================================================
Error: MSSQL:12:test connection pool concurrency

Error(COMM, "Unexpected EOF from the server")
------------------------------------------------------------------------------
Ran: 29 tests in: 0.01 seconds.
FAILED: Cases: 29 Tried: 29 Errors: 2 Failures: 0 Skip:  0 Todo: 0 Timeouts: 0.
.............................
Ran: 29 tests in: 0.01 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
............E................
==============================================================================
Error: MSSQL:12:test connection pool concurrency

Error(COMM, "Unexpected EOF from the server")
------------------------------------------------------------------------------
Ran: 29 tests in: 0.01 seconds.
FAILED: Cases: 29 Tried: 29 Errors: 1 Failures: 0 Skip:  0 Todo: 0 Timeouts: 0.
E............................
==============================================================================
Error: MSSQL:0:select and convert

Error(COMM, "Unexpected EOF from the server")
------------------------------------------------------------------------------
Ran: 29 tests in: 0.01 seconds.
FAILED: Cases: 29 Tried: 29 Errors: 1 Failures: 0 Skip:  0 Todo: 0 Timeouts: 0.

We also saw results like Error(COMM, "Operation now in progress"). Notice that the tests pass most of the time, and the tests that fail are completely random.

After some debugging, I tried switching our TDS version to 7.0 (since we don't actually use any features from TDS 7.1), and the flakiness immediately went away:

.............................
Ran: 29 tests in: 0.01 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
.............................
Ran: 29 tests in: 0.01 seconds.
OK
# etc.

I hope this saves someone else a few hours of debugging.