Skip to content
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

Deadlock happens when two theads concurrently read from _cache dictionary #22

Closed
Igor-Palaguta opened this issue Jul 15, 2017 · 0 comments · Fixed by #23
Closed

Deadlock happens when two theads concurrently read from _cache dictionary #22

Igor-Palaguta opened this issue Jul 15, 2017 · 0 comments · Fixed by #23
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Igor-Palaguta
Copy link

Hello,

Version: Vapor 2.1.2, Routing 2.0.0
Xcode 8.3.2/Debug

Very frequently deadlock happens, when two threads at same time read from _cache dictionary. Probably it is Foundation issue, as multiple reads should be allowed. Currently read and write operations for _cache are not synchronized. Probably _cache is corrupted after two threads modify it at same time.

Here is stack:

Thread 2 Queue : codes.vapor.server (concurrent)
#0	0x00000001013476f9 in specialized static String.== infix(String, String) -> Bool ()
#1	0x00000001013052c1 in protocol witness for static Equatable.== infix(A, A) -> Bool in conformance String ()
#2	0x00000001012696ff in _NativeDictionaryBuffer<A, B where ...>._find(A, startBucket : Int) -> (pos : _NativeDictionaryIndex<A, B>, found : Bool) ()
#3	0x0000000101277859 in _NativeDictionaryBuffer<A, B where ...>.maybeGet(A) -> B? ()
#4	0x0000000101265c36 in _VariantDictionaryBuffer.maybeGet(A) -> B? ()
#5	0x000000010123a4be in Dictionary.subscript.getter ()
#6	0x0000000100857662 in Router.route(Request) -> Responder? at /Users/Igor/Projects/TennisCup/.build/checkouts/routing.git-5366657101075133678/Sources/Routing/Router.swift:35
#7	0x0000000100853744 in Router.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/routing.git-5366657101075133678/Sources/Routing/Router+Responder.swift:9
#8	0x000000010085501b in protocol witness for Responder.respond(to : Request) throws -> Response in conformance Router ()
#9	0x0000000100917062 in SessionsMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Sessions/SessionsMiddleware.swift:52
#10	0x0000000100917e53 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance SessionsMiddleware ()
#11	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#12	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#13	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#14	0x00000001009ce3fe in FileMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileMiddleware.swift:21
#15	0x00000001009cf1a3 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance FileMiddleware ()
#16	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#17	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#18	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#19	0x00000001009a57bc in DateMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Date/DateMiddleware.swift:36
#20	0x00000001009a6e63 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance DateMiddleware ()
#21	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#22	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#23	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#24	0x00000001009bfc3b in ErrorMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorMiddleware.swift:17
#25	0x00000001009c27b3 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance ErrorMiddleware ()
#26	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#27	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#28	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#29	0x00000001009b12bb in Droplet.(init(config : Config?, router : Router?, server : ServerFactoryProtocol?, client : ClientFactoryProtocol?, middleware : [Middleware]?, console : ConsoleProtocol?, log : LogProtocol?, hash : HashProtocol?, cipher : CipherProtocol?, commands : [Command]?, view : ViewRenderer?, cache : CacheProtocol?, mail : MailProtocol?) throws -> Droplet).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet.swift:146
#30	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#31	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#32	0x00000001005a56f3 in BasicServer.respond(stream : A.Client, responder : Responder) throws -> () at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Server/BasicServer.swift:96
#33	0x00000001005a4f91 in BasicServer.(start(Responder, errors : (ServerError) -> ()) throws -> ()).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Server/BasicServer.swift:53
Thread 4 Queue : codes.vapor.server (concurrent)
#0	0x000000010140bb4a in _swift_retain_ ()
#1	0x00000001013c5704 in initializeWithCopy for String ()
#2	0x00000001012696da in _NativeDictionaryBuffer<A, B where ...>._find(A, startBucket : Int) -> (pos : _NativeDictionaryIndex<A, B>, found : Bool) ()
#3	0x0000000101277859 in _NativeDictionaryBuffer<A, B where ...>.maybeGet(A) -> B? ()
#4	0x0000000101265c36 in _VariantDictionaryBuffer.maybeGet(A) -> B? ()
#5	0x000000010123a4be in Dictionary.subscript.getter ()
#6	0x0000000100857662 in Router.route(Request) -> Responder? at /Users/Igor/Projects/TennisCup/.build/checkouts/routing.git-5366657101075133678/Sources/Routing/Router.swift:35
#7	0x0000000100853744 in Router.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/routing.git-5366657101075133678/Sources/Routing/Router+Responder.swift:9
#8	0x000000010085501b in protocol witness for Responder.respond(to : Request) throws -> Response in conformance Router ()
#9	0x0000000100917062 in SessionsMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Sessions/SessionsMiddleware.swift:52
#10	0x0000000100917e53 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance SessionsMiddleware ()
#11	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#12	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#13	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#14	0x00000001009ce3fe in FileMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/File/FileMiddleware.swift:21
#15	0x00000001009cf1a3 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance FileMiddleware ()
#16	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#17	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#18	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#19	0x00000001009a57bc in DateMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Date/DateMiddleware.swift:36
#20	0x00000001009a6e63 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance DateMiddleware ()
#21	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#22	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#23	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#24	0x00000001009bfc3b in ErrorMiddleware.respond(to : Request, chainingTo : Responder) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Error/ErrorMiddleware.swift:17
#25	0x00000001009c27b3 in protocol witness for Middleware.respond(to : Request, chainingTo : Responder) throws -> Response in conformance ErrorMiddleware ()
#26	0x00000001009f23a3 in Collection<A where ...>.(chain(to : Responder) -> Responder).(closure #1).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Middleware/Chaining.swift:15
#27	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#28	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#29	0x00000001009b12bb in Droplet.(init(config : Config?, router : Router?, server : ServerFactoryProtocol?, client : ClientFactoryProtocol?, middleware : [Middleware]?, console : ConsoleProtocol?, log : LogProtocol?, hash : HashProtocol?, cipher : CipherProtocol?, commands : [Command]?, view : ViewRenderer?, cache : CacheProtocol?, mail : MailProtocol?) throws -> Droplet).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/vapor.git-5492988889259800272/Sources/Vapor/Droplet/Droplet.swift:146
#30	0x0000000100597d02 in BasicResponder.respond(to : Request) throws -> Response at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Responder/Responder.swift:13
#31	0x0000000100597da4 in protocol witness for Responder.respond(to : Request) throws -> Response in conformance BasicResponder ()
#32	0x00000001005a56f3 in BasicServer.respond(stream : A.Client, responder : Responder) throws -> () at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Server/BasicServer.swift:96
#33	0x00000001005a4f91 in BasicServer.(start(Responder, errors : (ServerError) -> ()) throws -> ()).(closure #1) at /Users/Igor/Projects/TennisCup/.build/checkouts/engine.git-3311994267206676365/Sources/HTTP/Server/BasicServer.swift:53
@tanner0101 tanner0101 added the bug Something isn't working label Jul 19, 2017
@tanner0101 tanner0101 added this to the 2.0.1 milestone Jul 19, 2017
@tanner0101 tanner0101 self-assigned this Jul 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants