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

Error: execution of an external program failed #210

Open
Yakumo-Yukari opened this issue Feb 9, 2025 · 14 comments · May be fixed by #211
Open

Error: execution of an external program failed #210

Yakumo-Yukari opened this issue Feb 9, 2025 · 14 comments · May be fixed by #211

Comments

@Yakumo-Yukari
Copy link

norm 2.8.6

Hint: \src\app.exe [Exec]
could not load: libpq.dll
Error: execution of an external program failed: 'src\app.exe'

I am using the SQLite3 database, and after upgrading to version 2.8.6, the program is not running properly.

@moigagoo
Copy link
Owner

moigagoo commented Feb 9, 2025

Interesting, you don't import norm/postgres by chance?

@Yakumo-Yukari
Copy link
Author

Interesting, you don't import norm/postgres by chance?

Image

I searched through my entire project code and am very sure that norm/postgres is not imported. The project runs normally with norm version 2.8.4, but an exception occurs when upgrading to 2.8.6.

@moigagoo
Copy link
Owner

The project runs normally with norm version 2.8.4, but an exception occurs when upgrading to 2.8.6.

And what about 2.8.5?

@Yakumo-Yukari
Copy link
Author

The project runs normally with norm version 2.8.4, but an exception occurs when upgrading to 2.8.6.

And what about 2.8.5?

2.8.5 works fine, 2.8.6 will report errors

@moigagoo
Copy link
Owner

@Yakumo-Yukari Thanks for the clarification!

Would you mind checking that this issue isn't related to the recent Nim 2.2.2 update?

It's just that I'm not seeing anything that could add this new libpq dependency in 2.8.6: 2.8.5...2.8.6. So I'm thinking maybe Nim's import internals have been updated.

@Yakumo-Yukari
Copy link
Author

@Yakumo-Yukari Thanks for the clarification!

Would you mind checking that this issue isn't related to the recent Nim 2.2.2 update?

It's just that I'm not seeing anything that could add this new libpq dependency in 2.8.6: 2.8.5...2.8.6. So I'm thinking maybe Nim's import internals have been updated.

os : win11

I'm using nim 2.2.0 and haven't upgraded to 2.2.2 yet.

@moigagoo
Copy link
Owner

@PhilippMDoerner could you please take a look at your latest PR and check why pool module might suddenly start requiring libpq?

@PhilippMDoerner
Copy link
Collaborator

That one comes out to a total of 4 lines of codes in change, at the very minimum that connection is non obvious through implicit magic that I'm not seeing. For reference:

https://github.com/moigagoo/norm/pull/209/files

That is changing a proc declaration to a variable assignment in 2 cases to turn them into closures and changing a type signature to require a closure:

proc newPool*[T: sqlite.DbConn](defaultSize: Positive, getDbProc: proc(): sqlite.DbConn {.closure.} = sqlite.getDb, poolExhaustedPolicy = pepRaise): Pool[T] =

As well as 1 fix of a double-import of std/os

None of that hints at suddenly requiring libpq anywhere. The best I can think of is that the closure somehow causes something to not be treeshaken that was treeshaken out before ?

@moigagoo
Copy link
Owner

I think the problem is in this line:

let getDb* = proc(): DbConn {.closure.} =

Since getDb is actually created and not just declared (as it would have been if the line was proc getDb*: DbConn), postgres.DbConn instance is being initiated and fails.

@PhilippMDoerner
Copy link
Collaborator

PhilippMDoerner commented Feb 10, 2025

That brings us somewhat into a catch-22: Without that you can't assign getDb as a defaultvalue to pool, as long as it still requires a closure.

So quick fix options thus are:

  • remove the default assignment and everybody can write let myGetDb = proc() : DbConn {.closure.} = normsSqliteModule.getDb() in their own codebase
  • remove closure support - which means regressing another bug as without being able to capture environment kills a lot of dynamic usecases (such as the one I rely on)

A more general fix that might take time to find would be:

  • Figure out what part of the codebase leads to this intermingling between sqlite and postgres and see if we can split the code apart enough to prevent it from happening. I'm not even sure what that might require.

@moigagoo moigagoo linked a pull request Feb 13, 2025 that will close this issue
@moigagoo
Copy link
Owner

moigagoo commented Feb 13, 2025

@PhilippMDoerner I've opened a PR to attempt to fix this issue.

First off, I've separated the tests for SQLite an Postgres, so that we could test different backends in isolation and make sure SQLite functionality doesn't depend on Postgres libs.

Second, I did try replacing getDb declaration. The tests all pass on my machine, so I'd like to ask you to add a test case that would fail with proc getDb declaration and pass with let getDb declaration.

@moigagoo
Copy link
Owner

moigagoo commented Feb 18, 2025

@Yakumo-Yukari @PhilippMDoerner could you please try and test your codebases again this branch: https://github.com/moigagoo/norm/tree/feature/fix_pool_postgres_210

In your .nimble files, replace the Norm requirement line with this line:

requires "https://github.com/moigagoo/norm#9476b26dece340660046ece39fe58a039ee9232e"

@Yakumo-Yukari
Copy link
Author

@Yakumo-Yukari @PhilippMDoerner could you please try and test your codebases again this branch: https://github.com/moigagoo/norm/tree/feature/fix_pool_postgres_210

In your .nimble files, replace the Norm requirement line with this line:

requires "https://github.com/moigagoo/norm#9476b26dece340660046ece39fe58a039ee9232e"

Okay, now it's working.

@moigagoo
Copy link
Owner

Okay, now it's working.

Great!

If @PhilippMDoerner confirms that his code doesn't break either, I'll finalize that as a fix and cut a new release.

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

Successfully merging a pull request may close this issue.

3 participants