diff --git a/taosWS/connection.go b/taosWS/connection.go index 9611a11..ac2e436 100644 --- a/taosWS/connection.go +++ b/taosWS/connection.go @@ -59,7 +59,7 @@ func (tc *taosConn) generateReqID() uint64 { return atomic.AddUint64(&tc.requestID, 1) } -func newTaosConn(cfg *config) (*taosConn, error) { +func newTaosConn(ctx context.Context, cfg *config) (*taosConn, error) { endpointUrl := &url.URL{ Scheme: cfg.net, Host: fmt.Sprintf("%s:%d", cfg.addr, cfg.port), @@ -91,7 +91,9 @@ func newTaosConn(cfg *config) (*taosConn, error) { err = tc.connect() if err != nil { + logx.WithContext(ctx).Errorf("websocket 连接失败,err:%v", err) tc.Close() + return nil, err } return tc, nil } diff --git a/taosWS/connector.go b/taosWS/connector.go index 8259d09..9310ee9 100644 --- a/taosWS/connector.go +++ b/taosWS/connector.go @@ -36,7 +36,7 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) { if c.cfg.writeTimeout == 0 { c.cfg.writeTimeout = common.DefaultWriteWait } - tc, err := newTaosConn(c.cfg) + tc, err := newTaosConn(ctx, c.cfg) return tc, err }