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

BUG DETECTED: wait() error when using SwiftyRequest, CouchDB and NIO #1550

Open
pixelfrei opened this issue Mar 15, 2021 · 0 comments
Open

Comments

@pixelfrei
Copy link

pixelfrei commented Mar 15, 2021

Description

When I load a json document with SwiftyRequest and then want to save it to CouchDB I get a BUG DETECTED: wait() error message from NIO.

Xcode stops the execution here:
https://github.com/apple/swift-nio/blob/main/Sources/NIO/EventLoopFuture.swift#L913

Environment Details

macOS 11.2.3
Xcode 12.4
Swift 5.3.2

Kitura 2.9.200
Kitura-NIO 2.4.200
SwiftyRequest 3.2.200
Kitura-CouchDB 3.2.0

Error message

Precondition failed: BUG DETECTED: wait() must not be called when on an EventLoop.
Calling wait() on any EventLoop can lead to
- deadlocks
- stalling processing of other connections (Channels) that are handled on the EventLoop that wait was called on

Further information:
- current eventLoop: Optional(SelectableEventLoop { selector = Selector { descriptor = 29 }, thread = NIOThread(name = NIO-ELT-1-#0), scheduledTasks = PriorityQueue(count: 0): [] })
- event loop associated to future: SelectableEventLoop { selector = Selector { descriptor = 45 }, thread = NIOThread(name = NIO-ELT-2-#0) }: file SwiftyRequest-CouchDB/.build/checkouts/Kitura-NIO/Sources/KituraNet/ClientRequest.swift, line 592
2021-03-15 11:55:50.415669+0100 SwiftyRequest-CouchDB[34611:5062052] Precondition failed: BUG DETECTED: wait() must not be called when on an EventLoop.
Calling wait() on any EventLoop can lead to
- deadlocks
- stalling processing of other connections (Channels) that are handled on the EventLoop that wait was called on

Further information:
- current eventLoop: Optional(SelectableEventLoop { selector = Selector { descriptor = 29 }, thread = NIOThread(name = NIO-ELT-1-#0), scheduledTasks = PriorityQueue(count: 0): [] })
- event loop associated to future: SelectableEventLoop { selector = Selector { descriptor = 45 }, thread = NIOThread(name = NIO-ELT-2-#0) }: file SwiftyRequest-CouchDB/.build/checkouts/Kitura-NIO/Sources/KituraNet/ClientRequest.swift, line 592

Example

let restRequest = RestRequest(method: .get, url: "RestApiUrl.json")

restRequest.responseObject() { (restResponse: Result<RestResponse<RestApiDocument>, RestError>) in
    switch restResponse {
    case .success(let result):
        if let document = result.body {
            self.services.couchDBService.retrieveDB("database") { (database, error) in
                guard let database = database  else {
                    Log.error("Database not found")
                    return
                }
                database.create(document) { (databaseResponse, error) in
                    if databaseResponse != nil {
                        Log.info("Successful created: \(String(describing: databaseResponse?.id))")
                    }
                }
            }
        }
    case .failure(let error):
        Log.error("Client request failed with \(error)")
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant