Skip to content

Commit

Permalink
🐛 Prevent deadlock when mapping empty bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
elgohr committed Oct 9, 2023
1 parent 9cf5673 commit bbb7a0a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions localstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,19 @@ func (i *Instance) mapPorts(ctx context.Context, services []Service, containerId
return fmt.Errorf("localstack: could not inspect container: %w", err)
}
ports := startedContainer.NetworkSettings.Ports
i.portMappingMutex.Lock()
defer i.portMappingMutex.Unlock()
if i.fixedPort {
bindings := ports[nat.Port(FixedPort.Port)]
if len(bindings) == 0 {
time.Sleep(time.Second)
return i.mapPorts(ctx, services, containerId, try+1)
}
i.portMappingMutex.Lock()
defer i.portMappingMutex.Unlock()
i.portMapping[FixedPort] = "localhost:" + bindings[0].HostPort
} else {
hasFilteredServices := len(services) > 0
i.portMappingMutex.Lock()
defer i.portMappingMutex.Unlock()
for service := range AvailableServices {
if hasFilteredServices && containsService(services, service) {
i.portMapping[service] = "localhost:" + ports[nat.Port(service.Port)][0].HostPort
Expand Down

0 comments on commit bbb7a0a

Please sign in to comment.