-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a crash when several request for the same URL or route are launched together #399
Conversation
ea33963
to
161488c
Compare
|
161488c
to
8756aba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thanks, @pvzig I want to run some tests again before merging this PR as I found something interesting with the change I didn't saw before. |
faf3a6e
to
90a99cd
Compare
* Fix a crash when several request for the same URL are launched concurrently regarding a race condition * Fix an issue in the `testStopActiveConnection` causing the `URLSession.share` singleton was stuck in the thread and it doesn’t work in another tests * Refactor the `SwifterTestsHttpRouter` to reuse the `HttpRouter` object * Add new tests for the threading issue * Include the new tests added to the `XCTManifests.swift` * Update the XCTManifests.swift path in the swiftlint config file * Rename the jobs in CircleCI * Update the swift-tools-version for the `Package.swift`
Fix a crash when several request for the same URL or route are launched together
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