Skip to content

Commit

Permalink
Merge pull request checksum0#1 from triple-a/hotfix/data-race
Browse files Browse the repository at this point in the history
Hotfix/data race
  • Loading branch information
steveguo2triplea authored Dec 12, 2023
2 parents 23212fa + 80d28b8 commit f4e0ed2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
10 changes: 4 additions & 6 deletions electrum/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ func NewClientSSL(
return nil, err
}

// c.transportLock.Lock()
c.transport = transport
// c.transportLock.Unlock()
go c.listen()

return c, nil
Expand Down Expand Up @@ -213,6 +211,7 @@ func (s *Client) listen() {
return
case err := <-s.transport.Errors():
s.Error <- err
s.transport = nil
s.Shutdown()
case bytes := <-s.transport.Responses():
result := &container{
Expand Down Expand Up @@ -341,16 +340,15 @@ func (s *Client) Shutdown() {
if !s.IsShutdown() {
close(s.quit)
}

if s.transport != nil {
_ = s.transport.Close()
}
s.transport = nil
s.handlers = nil
s.pushHandlers = nil
if (s.txCache) != nil {
s.txCache.Close()
}
// s.transport = nil
s.handlers = nil
s.pushHandlers = nil
}

func (s *Client) IsShutdown() bool {
Expand Down
5 changes: 0 additions & 5 deletions electrum/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type TCPTransport struct {
conn net.Conn
responses chan []byte
errors chan error
isClosed bool
}

// DialerOption is a function that configures a TCPTransport.
Expand Down Expand Up @@ -101,9 +100,6 @@ func (t *TCPTransport) listen() {
t.errors <- err
break
}
if t.isClosed {
break
}
if DebugMode {
log.Printf(
"%s [debug] %s -> %s",
Expand Down Expand Up @@ -143,6 +139,5 @@ func (t *TCPTransport) Errors() <-chan error {
}

func (t *TCPTransport) Close() error {
t.isClosed = true
return t.conn.Close()
}

0 comments on commit f4e0ed2

Please sign in to comment.