- Is it possible to release a session while a call is in progress?
There are mutexes to prevent simultaneously reading and writing within a single session:
|
func (c *Core) readWriteDev( |
|
body []byte, |
|
acquired *session, |
|
mode CallMode, |
|
) ([]byte, error) { |
|
|
|
if mode == CallModeRead { |
|
if len(body) != 0 { |
|
return nil, errors.New("non-empty body on read mode") |
|
} |
|
c.log.Log("skipping write") |
|
} else { |
|
acquired.writeMutex.Lock() |
|
err := c.writeDev(body, acquired.dev) |
|
acquired.writeMutex.Unlock() |
|
if err != nil { |
|
return nil, err |
|
} |
|
} |
|
|
|
if mode == CallModeWrite { |
|
c.log.Log("skipping read") |
|
return []byte{0}, nil |
|
} |
|
acquired.readMutex.Lock() |
|
defer acquired.readMutex.Unlock() |
|
return c.readDev(acquired.dev) |
|
} |
I do not see the Release function acquiring locks for these mutexes so it seems like we'd be able to release a session whilst it's busy reading and writing? Perhaps I'm missing some libusb magic locking mechanisms here.
|
func (c *Core) release( |
|
ssid string, |
|
disconnected bool, |
|
debug bool, |
|
) error { |
|
c.log.Log(fmt.Sprintf("session %s", ssid)) |
|
s := c.sessions(debug) |
|
v, ok := s.Load(ssid) |
|
if !ok { |
|
c.log.Log("session not found") |
|
return ErrSessionNotFound |
|
} |
|
s.Delete(ssid) |
|
acquired := v.(*session) |
|
c.log.Log("bus close") |
|
err := acquired.dev.Close(disconnected) |
|
return err |
|
} |
|
|
There are locks on the session maps, but those only apply to adding and removing values within the map.
- Is that a desirable property?
If it's not a desirable and deliberate property then I'm willing to contribute a fix.
There are mutexes to prevent simultaneously reading and writing within a single session:
trezord-go/core/core.go
Lines 629 to 656 in 106e5e9
I do not see the
Releasefunction acquiring locks for these mutexes so it seems like we'd be able to release a session whilst it's busy reading and writing? Perhaps I'm missing somelibusbmagic locking mechanisms here.trezord-go/core/core.go
Lines 354 to 372 in 106e5e9
There are locks on the session maps, but those only apply to adding and removing values within the map.
If it's not a desirable and deliberate property then I'm willing to contribute a fix.