Skip to content

connect() hangs when server does not respond to pre-login #254

@datbth

Description

@datbth

Describe the bug
When connecting to a server that does not respond to pre-login packets, connect() would hang indefinitely.

To Reproduce

func TestSqlserverConnectTimeout(t *testing.T) {
	sd := sqlserver.Driver{}
	cntor, cntorErr := sd.OpenConnector("sqlserver://128.199.74.51:8000")
	if cntorErr != nil {
		panic(cntorErr)
	}

	ctx, cancelTimeout := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancelTimeout()

	_, connErr := cntor.Connect(ctx)
	assert.ErrorContains(t, connErr, "timeout")
}

Expected behavior
The above test passes (connErr is a timeout error)

Further technical details

I found that it hangs in readPrelogin(), at r.BeginRead()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions