Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
Fix current map write bug in rest bridge config
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Kim <kjosh@vmware.com>
  • Loading branch information
jooskim committed Feb 20, 2022
1 parent 77c3333 commit 172aa27
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions plank/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ func (ps *platformServer) SetHttpChannelBridge(bridgeConfig *service.RESTBridgeC
}
}

// NOTE: mux.Router does not have mutex or any locking mechanism so it could sometimes lead to concurrency write
// panics. the following is to ensure the modification to ps.router can happen only once per thread, this atomic
// counter also protects against concurrent writing to ps.endpointHandlerMap
for !atomic.CompareAndSwapInt32(ps.routerConcurrencyProtection, 0, 1) {
time.Sleep(1 * time.Nanosecond)
}

// build endpoint handler
ps.endpointHandlerMap[endpointHandlerKey] = ps.buildEndpointHandler(
bridgeConfig.ServiceChannel,
Expand All @@ -363,12 +370,6 @@ func (ps *platformServer) SetHttpChannelBridge(bridgeConfig *service.RESTBridgeC
permittedMethods = append(permittedMethods, http.MethodOptions)
}

// NOTE: mux.Router does not have mutex or any locking mechanism so it could sometimes lead to concurrency write
// panics. the following is to ensure the modification to ps.router can happen only once per thread
for !atomic.CompareAndSwapInt32(ps.routerConcurrencyProtection, 0, 1) {
time.Sleep(1 * time.Nanosecond)
}

ps.router.
Path(bridgeConfig.Uri).
Methods(permittedMethods...).
Expand Down

0 comments on commit 172aa27

Please sign in to comment.