diff --git a/x/mongo/driver/topology/pool.go b/x/mongo/driver/topology/pool.go index 89ae960887..b4001cb17a 100644 --- a/x/mongo/driver/topology/pool.go +++ b/x/mongo/driver/topology/pool.go @@ -902,8 +902,9 @@ func (p *pool) checkInNoEvent(conn *connection) error { // not usable, which is not covered by the current pool events. We may need // to add pool event information in the future to communicate that. if conn.awaitingResponse != nil { - go bgRead(p, conn, *conn.awaitingResponse) + size := *conn.awaitingResponse conn.awaitingResponse = nil + go bgRead(p, conn, size) return nil } diff --git a/x/mongo/driver/topology/pool_test.go b/x/mongo/driver/topology/pool_test.go index a837020395..815c0f5506 100644 --- a/x/mongo/driver/topology/pool_test.go +++ b/x/mongo/driver/topology/pool_test.go @@ -12,6 +12,7 @@ import ( "io" "net" "os" + "regexp" "sync" "testing" "time" @@ -1190,8 +1191,10 @@ func TestPool(t *testing.T) { ctx, cancel := csot.MakeTimeoutContext(context.Background(), time.Second) defer cancel() _, err = conn.readWireMessage(ctx) - assert.ErrorContains(t, err, - "incomplete read of message header: context deadline exceeded: read unix ->./test.sock: i/o timeout") + regex := regexp.MustCompile( + `^connection\(.*\[-\d+\]\) incomplete read of message header: context deadline exceeded: read unix .*->\.\/test.sock: i\/o timeout$`, + ) + assert.True(t, regex.MatchString(err.Error()), "mismatched err: %w", err) err = p.checkIn(conn) noerr(t, err) wg.Wait() @@ -1238,8 +1241,10 @@ func TestPool(t *testing.T) { ctx, cancel := csot.MakeTimeoutContext(context.Background(), time.Second) defer cancel() _, err = conn.readWireMessage(ctx) - assert.ErrorContains(t, err, - "incomplete read of message header: context deadline exceeded: read unix ->./test.sock: i/o timeout") + regex := regexp.MustCompile( + `^connection\(.*\[-\d+\]\) incomplete read of message header: context deadline exceeded: read unix .*->\.\/test.sock: i\/o timeout$`, + ) + assert.True(t, regex.MatchString(err.Error()), "mismatched err: %w", err) err = p.checkIn(conn) noerr(t, err) wg.Wait() @@ -1291,11 +1296,13 @@ func TestPool(t *testing.T) { conn, err := p.checkOut(context.Background()) noerr(t, err) - ctx, cancel := csot.MakeTimeoutContext(context.Background(), time.Second) + ctx, cancel := csot.MakeTimeoutContext(context.Background(), 1*time.Second) defer cancel() _, err = conn.readWireMessage(ctx) - assert.ErrorContains(t, err, - "incomplete read of full message: context deadline exceeded: read unix ->./test.sock: i/o timeout") + regex := regexp.MustCompile( + `^connection\(.*\[-\d+\]\) incomplete read of full message: context deadline exceeded: read unix .*->\.\/test.sock: i\/o timeout$`, + ) + assert.True(t, regex.MatchString(err.Error()), "mismatched err: %w", err) err = p.checkIn(conn) noerr(t, err) wg.Wait()