Skip to content

rpc_client.go: suspect locking (shutdownLock) #782

@hw-claudio

Description

@hw-claudio

In reference to:

https://github.com/hashicorp/serf/blob/93c69c072b854e28812e80a803ca769ed1f85999/client/rpc_client.go#L186C1-L189C1

To me the use of shutdownLock seems a bit suspect, as it seems to only prevent concurrent attempts to Close(),
which writes to bool variable "shutdown",

but does not protect calls to "IsClosed()", and all checks in the rpc_client.go code do not even go through IsClosed, they check directly
c.shutdown .

Compounding to this, the Close() function only closes after setting c.shutdown to true:

if !c.shutdown {
	c.shutdown = true
	close(c.shutdownCh)
	c.deregisterAll()
	return c.conn.Close()
  }

So it seems very much possible for code checking for IsClosed() to return true when it is not.

I would suggest to protect IsClosed using the shutdown mutex too,
and call into IsClosed() everywhere is rpc_client.go instead of checking c.shutdown directly.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions