vapor / sqlite-nio

Non-blocking wrapper for libsqlite3-dev using SwiftNIO
MIT License
61 stars 16 forks source link

fix: No longer fatal errors on inactive thread pool #44

Closed NeedleInAJayStack closed 1 year ago

NeedleInAJayStack commented 1 year ago

Previously, trying to open a connection on an inactive thread pool would throw Fatal error: leaking promise created at (file: "SQLiteNIO/SQLiteConnection.swift", line: 101). This was because the promise created on line 101 of SQLiteConnection.swift would not be succeeded or failed when the runIfActive was called on an inactive thread pool. To resolve this, we avoid creating a new Promise altogether, just using the one that runIfActive provides.

gwynne commented 1 year ago

🤔 I'm trying to work out why this was ever implemented like this. This looks like a good change though 👍

@gwynne any thoughts?

Because until I (finally) merged the custom functions support PR, this method - like most of the rest of SQLiteNIO - had been incorrectly implemented using NIOThreadPool.submit, not NIOThreadPool.runIfActive, which would call the work item body with an appropriate state (which the old implementation incorrectly ignored) in all cases. The promise leak is a new issue and a side effect of my incomplete review of the change I requested in the custom functions PR. Great catch, @NeedleInAJayStack! ❤️

VaporBot commented 1 year ago

These changes are now available in 1.4.1