-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from privacybydesign/fix-session-expiry-deadlock
Prevent possible mutex deadlock when using chained sessions
- Loading branch information
Showing
2 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package irmaserver | ||
|
||
import ( | ||
irma "github.com/privacybydesign/irmago" | ||
"github.com/privacybydesign/irmago/server" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestMemoryStoreNoDeadlock(t *testing.T) { | ||
logger := logrus.New() | ||
logger.Level = logrus.FatalLevel | ||
s, err := New(&server.Configuration{Logger: logger}) | ||
require.NoError(t, err) | ||
defer s.Stop() | ||
|
||
req, err := server.ParseSessionRequest(`{"request":{"@context":"https://irma.app/ld/request/disclosure/v2","context":"AQ==","nonce":"MtILupG0g0J23GNR1YtupQ==","devMode":true,"disclose":[[[{"type":"test.test.email.email","value":"[email protected]"}]]]}}`) | ||
require.NoError(t, err) | ||
session := s.newSession(irma.ActionDisclosing, req) | ||
|
||
session.Lock() | ||
deletingCompleted := false | ||
addingCompleted := false | ||
// Make sure the deleting continues on completion such that the test itself will not hang. | ||
defer func() { | ||
session.Unlock() | ||
time.Sleep(100 * time.Millisecond) | ||
require.True(t, deletingCompleted) | ||
}() | ||
|
||
go func() { | ||
s.sessions.deleteExpired() | ||
deletingCompleted = true | ||
}() | ||
|
||
// Make sure the goroutine above is running | ||
time.Sleep(100 * time.Millisecond) | ||
|
||
// Make a new session; this involves adding it to the memory session store. | ||
go func() { | ||
_ = s.newSession(irma.ActionDisclosing, req) | ||
addingCompleted = true | ||
}() | ||
|
||
// Check whether the IRMA server doesn't hang | ||
time.Sleep(100 * time.Millisecond) | ||
require.True(t, addingCompleted) | ||
require.False(t, deletingCompleted) | ||
} |