fixed the missing initialization in connecting to the server
This commit is contained in:
17
client.go
17
client.go
@@ -13,6 +13,7 @@ import "net"
|
|||||||
import "net/http"
|
import "net/http"
|
||||||
import "os"
|
import "os"
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
|
import "runtime"
|
||||||
import "slices"
|
import "slices"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
import "strings"
|
import "strings"
|
||||||
@@ -1106,6 +1107,7 @@ func (cts *ClientConn) disconnect_from_server(logmsg bool) {
|
|||||||
cts.rpx_mtx.Unlock()
|
cts.rpx_mtx.Unlock()
|
||||||
|
|
||||||
// don't care about double closes when this function is called from both RunTask() and ReqStop()
|
// don't care about double closes when this function is called from both RunTask() and ReqStop()
|
||||||
|
if cts.psc != nil { cts.psc.CloseSend() }
|
||||||
cts.conn.Close()
|
cts.conn.Close()
|
||||||
|
|
||||||
// don't reset cts.conn to nil here
|
// don't reset cts.conn to nil here
|
||||||
@@ -1302,7 +1304,7 @@ func (cts *ClientConn) dispatch_packet(pkt *Packet) bool {
|
|||||||
func (cts *ClientConn) RunTask(wg *sync.WaitGroup) {
|
func (cts *ClientConn) RunTask(wg *sync.WaitGroup) {
|
||||||
var psc PacketStreamClient
|
var psc PacketStreamClient
|
||||||
var slpctx context.Context
|
var slpctx context.Context
|
||||||
var cancel_sleep context.CancelFunc
|
var slpctx_cancel context.CancelFunc
|
||||||
var c_seed Seed
|
var c_seed Seed
|
||||||
var s_seed *Seed
|
var s_seed *Seed
|
||||||
var p *peer.Peer
|
var p *peer.Peer
|
||||||
@@ -1318,6 +1320,8 @@ start_over:
|
|||||||
cts.State.Store(CLIENT_CONN_CONNECTING)
|
cts.State.Store(CLIENT_CONN_CONNECTING)
|
||||||
cts.cfg.Index = (cts.cfg.Index + 1) % len(cts.cfg.ServerAddrs)
|
cts.cfg.Index = (cts.cfg.Index + 1) % len(cts.cfg.ServerAddrs)
|
||||||
cts.C.log.Write(cts.Sid, LOG_INFO, "Connecting to server[%d] %s", cts.cfg.Index, cts.cfg.ServerAddrs[cts.cfg.Index])
|
cts.C.log.Write(cts.Sid, LOG_INFO, "Connecting to server[%d] %s", cts.cfg.Index, cts.cfg.ServerAddrs[cts.cfg.Index])
|
||||||
|
|
||||||
|
opts = []grpc.DialOption{ }
|
||||||
if cts.C.rpc_tls == nil {
|
if cts.C.rpc_tls == nil {
|
||||||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if cts.cfg.ServerAuthority != "" { opts = append(opts, grpc.WithAuthority(cts.cfg.ServerAuthority)) }
|
if cts.cfg.ServerAuthority != "" { opts = append(opts, grpc.WithAuthority(cts.cfg.ServerAuthority)) }
|
||||||
@@ -1458,17 +1462,19 @@ reconnect_to_server:
|
|||||||
cts.State.Store(CLIENT_CONN_DISCONNECTED)
|
cts.State.Store(CLIENT_CONN_DISCONNECTED)
|
||||||
cts.C.FireConnEvent(CLIENT_EVENT_CONN_UPDATED, cts)
|
cts.C.FireConnEvent(CLIENT_EVENT_CONN_UPDATED, cts)
|
||||||
|
|
||||||
|
runtime.GC()
|
||||||
|
|
||||||
// wait for 2 seconds
|
// wait for 2 seconds
|
||||||
slpctx, cancel_sleep = context.WithTimeout(cts.C.Ctx, 2 * time.Second)
|
slpctx, slpctx_cancel = context.WithTimeout(cts.C.Ctx, 2 * time.Second)
|
||||||
select {
|
select {
|
||||||
case <-cts.C.Ctx.Done():
|
case <-cts.C.Ctx.Done():
|
||||||
// need to log cts.C.Ctx.Err().Error()?
|
// need to log cts.C.Ctx.Err().Error()?
|
||||||
cancel_sleep()
|
slpctx_cancel()
|
||||||
goto req_stop_and_wait_for_termination
|
goto req_stop_and_wait_for_termination
|
||||||
case <-cts.stop_chan:
|
case <-cts.stop_chan:
|
||||||
// this signal indicates that ReqStop() has been called
|
// this signal indicates that ReqStop() has been called
|
||||||
// so jump to the waiting label
|
// so jump to the waiting label
|
||||||
cancel_sleep()
|
slpctx_cancel()
|
||||||
goto wait_for_termination
|
goto wait_for_termination
|
||||||
case <-slpctx.Done():
|
case <-slpctx.Done():
|
||||||
select {
|
select {
|
||||||
@@ -1483,7 +1489,7 @@ reconnect_to_server:
|
|||||||
// do nothing. go on
|
// do nothing. go on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cancel_sleep()
|
slpctx_cancel()
|
||||||
goto start_over // and reconnect
|
goto start_over // and reconnect
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1502,7 +1508,6 @@ func (cts *ClientConn) ReportPacket(route_id RouteId, pts_id PeerId, packet_type
|
|||||||
return r.ReportPacket(pts_id, packet_type, event_data)
|
return r.ReportPacket(pts_id, packet_type, event_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// rpty
|
// rpty
|
||||||
func (cts *ClientConn) FindClientRptyById(id uint64) *ClientRpty {
|
func (cts *ClientConn) FindClientRptyById(id uint64) *ClientRpty {
|
||||||
var crp *ClientRpty
|
var crp *ClientRpty
|
||||||
|
|||||||
Reference in New Issue
Block a user