Fix a crash when several request for the same URL or route are launched together #399
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This issue was detected by one of my colleagues during some UI Tests research using Xcode 10.2. When I started to test the branch with the issue using Charles I detected an issue coming from several requests being launched in very close intervals when they belong to similar routers or even the same route.
The issue was causing an
EXC_BAD_INSTRUCTION
:Once I enabled the Thread Sanitizer for the test suite I was able to follow the path to localize the issue causing the thread race condition and it was coming from:
swifter/XCode/Sources/HttpServerIO.swift
Line 88 in 70ec292
Apparently, there were some issues during starting and stopping new connections during concurrent requests. I was able to reproduce it in the library simulating several requests concurrent and serial with time differences in the new
ServerThreadingTests
.This PR can be resumed in the following steps:
testStopActiveConnection
causing theURLSession.share
singleton was stuck in the thread and it wasn't working in subsequent testsSwifterTestsHttpRouter
to reuse theHttpRouter
objectXCTManifests.swift