Skip to content

Commit

Permalink
refactor: lock when to call GetLastError since it might be in communi…
Browse files Browse the repository at this point in the history
…cation
  • Loading branch information
t2y committed Jun 22, 2023
1 parent 2f623f0 commit 9de41ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ func (l *Conn) nextMessageID() int64 {
// GetLastError returns the last recorded error from goroutines like processMessages and reader.
// Only the last recorded error will be returned.
func (l *Conn) GetLastError() error {
l.messageMutex.Lock()
defer l.messageMutex.Unlock()
return l.err
}

Expand Down
2 changes: 2 additions & 0 deletions v3/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ func (l *Conn) nextMessageID() int64 {
// GetLastError returns the last recorded error from goroutines like processMessages and reader.
// // Only the last recorded error will be returned.
func (l *Conn) GetLastError() error {
l.messageMutex.Lock()
defer l.messageMutex.Unlock()
return l.err
}

Expand Down

0 comments on commit 9de41ce

Please sign in to comment.