Skip to content

Commit

Permalink
fix: fix the problem of session (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 authored Apr 13, 2022
1 parent 22452b5 commit a3f4c56
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ccore/nebula/client_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type (
Close() error
Factory() Factory
Version() Version
GetTimezoneInfo() types.TimezoneInfo
}

defaultGraphClient defaultClient
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion ccore/nebula/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type (
username string
password string
sessionId int64
timezone types.TimezoneInfo
}

driverMeta struct {
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 3 additions & 14 deletions ccore/nebula/gateway/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Client struct {
updateTime int64
parameterMap types.ParameterMap
account *Account
timezone types.TimezoneInfo
}

type ClientInfo struct {
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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) {
Expand All @@ -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())
}
Expand Down

0 comments on commit a3f4c56

Please sign in to comment.