Skip to content

Commit

Permalink
Fix singleton can no longer be used after being closed
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming authored and jsouthworth committed Mar 23, 2021
1 parent 19e024a commit 6f46e0d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ type Conn struct {
func SessionBus() (conn *Conn, err error) {
sessionBusLck.Lock()
defer sessionBusLck.Unlock()
if sessionBus != nil {
if sessionBus != nil &&
sessionBus.Connected() {
return sessionBus, nil
}
defer func() {
Expand Down Expand Up @@ -105,7 +106,8 @@ func SessionBusPrivateHandler(handler Handler, signalHandler SignalHandler) (*Co
func SystemBus() (conn *Conn, err error) {
systemBusLck.Lock()
defer systemBusLck.Unlock()
if systemBus != nil {
if systemBus != nil &&
systemBus.Connected() {
return systemBus, nil
}
defer func() {
Expand Down Expand Up @@ -328,6 +330,11 @@ func (conn *Conn) Context() context.Context {
return conn.ctx
}

// Connected returns whether conn is connected
func (conn *Conn) Connected() bool {
return conn.ctx.Err() == nil
}

// Eavesdrop causes conn to send all incoming messages to the given channel
// without further processing. Method replies, errors and signals will not be
// sent to the appropriate channels and method calls will not be handled. If nil
Expand Down

0 comments on commit 6f46e0d

Please sign in to comment.