From a3f4c56287d853c92bc80df19eebf25ef8db7a76 Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Wed, 13 Apr 2022 19:34:47 +0800 Subject: [PATCH] fix: fix the problem of session (#98) --- ccore/nebula/client_graph.go | 5 +++++ ccore/nebula/driver.go | 8 +++++++- ccore/nebula/gateway/pool/pool.go | 17 +++-------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ccore/nebula/client_graph.go b/ccore/nebula/client_graph.go index a39a345..d6b7665 100644 --- a/ccore/nebula/client_graph.go +++ b/ccore/nebula/client_graph.go @@ -15,6 +15,7 @@ type ( Close() error Factory() Factory Version() Version + GetTimezoneInfo() types.TimezoneInfo } defaultGraphClient defaultClient @@ -34,6 +35,10 @@ func NewGraphClient(endpoints []string, username, password string, opts ...Optio return c.Graph(), nil } +func (c *defaultGraphClient) GetTimezoneInfo() types.TimezoneInfo { + return c.graph.GetTimezoneInfo() +} + func (c *defaultGraphClient) Open() error { return c.defaultClient().initDriver(func(driver types.Driver) error { return c.graph.open(driver) diff --git a/ccore/nebula/driver.go b/ccore/nebula/driver.go index ecc6b42..7fa98dc 100644 --- a/ccore/nebula/driver.go +++ b/ccore/nebula/driver.go @@ -18,6 +18,7 @@ type ( username string password string sessionId int64 + timezone types.TimezoneInfo } driverMeta struct { @@ -105,13 +106,18 @@ func (d *driverGraph) open(driver types.Driver) error { panic("sessionId can not be nil after authenticate") } d.sessionId = *sessionId - + d.timezone = resp.GetTimezoneInfo() d.GraphClientDriver = graphClientDriver return nil } +func (d *driverGraph) GetTimezoneInfo() types.TimezoneInfo { + return d.timezone +} + func (d *driverGraph) close() error { if d.GraphClientDriver != nil { + d.GraphClientDriver.Signout(d.sessionId) if err := d.GraphClientDriver.Close(); err != nil { return err } diff --git a/ccore/nebula/gateway/pool/pool.go b/ccore/nebula/gateway/pool/pool.go index 4045f1a..e9107e6 100644 --- a/ccore/nebula/gateway/pool/pool.go +++ b/ccore/nebula/gateway/pool/pool.go @@ -55,6 +55,7 @@ type Client struct { updateTime int64 parameterMap types.ParameterMap account *Account + timezone types.TimezoneInfo } type ClientInfo struct { @@ -239,6 +240,7 @@ func NewClient(address string, port int, username string, password string, opts username: username, password: password, }, + timezone: c.GetTimezoneInfo(), } clientPool[ncid] = client currentClientNum++ @@ -286,19 +288,6 @@ func handleRequest(ncid string) { } if len(request.Gql) > 0 { - // use auth response to get timezone info - authResp, err := client.graphClient.Authenticate(client.account.username, client.account.password) - if err != nil { - if isThriftProtoError(err) || isThriftTransportError(err) { - err = fmt.Errorf("%s. %s.\n", err.Error(), InterruptError.Error()) - } - request.ResponseChannel <- ChannelResponse{ - Result: nil, - Error: err, - } - return - } - execResponse, err := client.graphClient.ExecuteWithParameter([]byte(request.Gql), client.parameterMap) if err != nil { if isThriftProtoError(err) || isThriftTransportError(err) { @@ -311,7 +300,7 @@ func handleRequest(ncid string) { return } - res, err := wrapper.GenResultSet(execResponse, client.graphClient.Factory(), authResp.GetTimezoneInfo()) + res, err := wrapper.GenResultSet(execResponse, client.graphClient.Factory(), client.timezone) if err != nil { err = fmt.Errorf("%s. %s.\n", err.Error(), InterruptError.Error()) }