Skip to content

Commit 22adf0f

Browse files
authored
Fix IDP deadlock due to recursive locking (crewjam#553)
While using the IDP server for integration tests, I've experienced a deadlock after issuing many concurrent requests to the following endpoints: - PUT /services/:id - GET /sso Apparently, the issue is that the IDP code attempts to acquires locks on the Server.idpConfigMu recursively: 1. The /sso HTTP handler calls Server.idpConfigMu.RLock() 2. Before releasing the above lock, this same handler eventually calls s.GetServiceProvider, which in turn attempts to acquire the same lock by calling Server.idpConfigMu.RLock() 3. Concurrent requests to `PUT /services/:id` acquire a write lock by calling Server.idpConfigMu.Lock() Step (2) is a recursive lock, which won't work, as stated by the documentation of sync.RWLock[1]: If a goroutine holds a RWMutex for reading and another goroutine might call Lock, no goroutine should expect to be able to acquire a read lock until the initial read lock is released. In particular, this prohibits recursive read locking. This is to ensure that the lock eventually becomes available; a blocked Lock call excludes new readers from acquiring the lock. This patch fixes the issue by removing the unnecessary lock acquired in step (1). This was redundant since GetServiceProvider() already takes care of serializing access to the s.serviceProviders map, which is the resource in question. [1] https://golang.org/pkg/sync/#RWMutex
1 parent d5c1c1a commit 22adf0f

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

samlidp/samlidp.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ func (s *Server) InitializeHTTP() {
9393
s.IDP.ServeMetadata(w, r)
9494
})
9595
mux.Handle("/sso", func(w http.ResponseWriter, r *http.Request) {
96-
s.idpConfigMu.RLock()
97-
defer s.idpConfigMu.RUnlock()
9896
s.IDP.ServeSSO(w, r)
9997
})
10098

0 commit comments

Comments
 (0)