Pack operations fail after upgrading swi-prolog to 9.2.1

I reported `pack` operations fail with `close_range` · Issue #164 · SWI-Prolog/packages-http · GitHub but am also reporting here. Most of the pack operations seem to fail with swi-prolog 9.2.1, and I can’t install any packages.

The error involves close_range, which seems to have been added to 9.2.1 with FIXED: http_open/3: avoid TSL handshake error when reading data · SWI-Prolog/packages-http@1e70298 · GitHub.

The trace looks like this:

?- pack_list(graph).
% Contacting server at https://www.swi-prolog.org/pack/query ...
ERROR: https://www.swi-prolog.org/pack/query:1:
ERROR:    Unknown procedure: system:close_range/3
ERROR:    In:
ERROR:      [20] close_range(<stream>(0x600001093e00,0x600001093f00),<stream>(0x600001093e00),0)
ERROR:      [19] call(system:close_range(<stream>(0x600001093e00,0x600001093f00)),<stream>(0x600001093e00),0) at /opt/homebrew/Cellar/swi-prolog/9.2.1/lib/swipl/boot/init.pl:506
ERROR:      [18] <meta call>
ERROR:      [17] close(<stream>(0x6000010dc400)) <foreign>
ERROR:      [16] <meta call>
ERROR:      [15] setup_call_cleanup(prolog_pack:http_open('https://www.swi-prolog.org/pack/query',<stream>(0x6000010dc400),...),prolog_pack:read_reply('application/x-prolog; charset=UTF-8',<stream>(0x6000010dc400),...),prolog_pack:close(<stream>(0x6000010dc400))) <foreign>
ERROR:      [14] prolog_pack:query_pack_server(search(graph),true([...|...]),[]) at /opt/homebrew/Cellar/swi-prolog/9.2.1/lib/swipl/library/prolog_pack.pl:2906
ERROR:      [13] prolog_pack:pack_list(graph,[]) at /opt/homebrew/Cellar/swi-prolog/9.2.1/lib/swipl/library/prolog_pack.pl:436
ERROR:      [11] toplevel_call(user:user: ...) at /opt/homebrew/Cellar/swi-prolog/9.2.1/lib/swipl/boot/toplevel.pl:1317
ERROR:
ERROR:    Note: some frames are missing due to last-call optimization.
ERROR:    Re-run your program in debug mode (:- debug.) to get more detail.
   Exception: (20) close_range(<stream>(0x600001093e00,0x600001093f00), <stream>(0x600001093e00), 0)

I’m having similar issues. But I responded by clearing out my SWI-Prolog installs and starting over, and am now in some python related hell.

1 Like

I finally got at least some swipl running by using the GUI snap installer, which installed 9.2.1

Doing so got me proper behavior for pack_list/1

Welcome to SWI-Prolog (threaded, 64 bits, version 9.2.1)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- pack_list(graph).
% Contacting server at https://www.swi-prolog.org/pack/query … ok
callgraph@.4.1 - Predicate call graph visualisation
disp_bn@.1 - Construct and display BN terms via graphviz
graphml@.1.0 - Write GraphML files
graphpl@.1.1 - Graph data structure utilities
graphql@.0.1 - GraphQL Prolog Library
graphql-swipl@.0.1 - GraphQL Prolog Library
gvterm@.1 - Show Prolog terms using graphviz
logicmoo_cg@.0.3 - Conceptual Graph (CG) Libraries in Prolog and test data
musicbrainz@.7.0 - Musicbrainz client library
plcairo@.1.1 - plcairo - Prolog bindings for cairo graphics library
prolog_graphviz@.0.5 - Prolog-based graph visualization
pub_graph@.2 - Access, cache and visualise citation relations in publications servers
sindice@.0.5 - Access to Sindice semantic web search engine
sourcehut@.1.10 - SourceHut GraphQL API client
wgraph@.6 - Weighted graphs, with plotting via Real
true.

1 Like

Interesting. But I see this error not only from pack operations but from other https connections using http_open. When the opened https (vs http) sessions are closed, I see the same errors about system:close_range/3.

Works fine here. What is weird is that it tries to call close_range/3 in system. It should do so in the module http_open`.

I don’t have a good explanation. A lot of problems with upgrades to 9.2/9.3 are caused by the fact that many files have changed location and thus installing the new version over an old version causes the existence of both old and new versions of these files. Depending on how you install the system, you may have to wipe the old installation before installing this. This notably applies if you install from source. If you install using the Windows installer, make sure to check the box to wipe the old installation first.

I’m not sure this is the cause here. The range stream that is now use for HTTPS data is in use for many years for Keep-alive connections.

I’m on Mac. I installed (upgraded) swi-prolog from homebrew.

I tried a couple things.

  • Uninstalled and re-installed with homebrew.
  • Uninstalled the homebrew version and installed using the installer from SWI-Prolog downloads.

But I still get the same error from both – swipl still tries to call system:close_range/3. The homebrew version uses /opt/homebrew/Cellar/swi-prolog/9.2.1/lib/swipl/library/prolog_pack.pl while the version from swi-prolog.org uses /Applications/SWI-Prolog.app/Contents/swipl/library/prolog_pack.pl, but they cause the same error.

I also tried installing 9.3.1 from swi-prolog.org. Still the same… Sigh…

I notice one thing weird in the stack trace.

setup_call_cleanup(prolog_pack:http_open('https://www.swi-prolog.org/pack/query',<stream>(0x6000010dc400),...),prolog_pack:read_reply('application/x-prolog; charset=UTF-8',<stream>(0x6000010dc400),...),prolog_pack:close(<stream>(0x6000010dc400))) <foreign>

http_open and close are shown as prolog_pack:http_open and prolog_pack:close. http_open should be coming from the http_open module and close should be built-in. They seem related to the error that I’m seeing.

Maybe the problem is the module http/http_open is garbage collected too early and swipl fails to find http_open:close_range/3? I suspect this because I see a slightly different stack trace sometimes.

Sometimes, the stack trace shows <garbage collected> instead of prolog_pack:http_open('...') in the same place that I pointed to in my earlier posting.

The problem reproduces on the Mac. It is rather weird that this is platform dependent, but it seems to be the case :frowning:

Fixed with a patch to packages/http on the range stream (C) code (use-after-free). This is a rather serious old bug that now becomes urgent :frowning: I think the brew installer allows installing from the git HEAD. That should fix things for you.

I’ll probably do a re-release of the MacOS binaries.

2 Likes

Awesome. Thanks for the quick fix, Jan!

I installed from HEAD using brew and I can confirm that I don’t see this problem anymore. Thanks again!

~ % swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.1-5-ga352222e1)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- pack_list(graph).
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
p callgraph@0.4.1                  - Predicate call graph visualisation
p disp_bn@0.1                      - Construct and display BN terms via graphviz
p graphml@0.1.0                    - Write GraphML files
p graphpl@0.1.1                    - Graph data structure utilities
p graphql@0.0.1                    - GraphQL Prolog Library
p graphql-swipl@0.0.1              - GraphQL Prolog Library
p gvterm@1.1                       - Show Prolog terms using graphviz
p logicmoo_cg@2.0.3                - Conceptual Graph (CG) Libraries in Prolog and test data
p musicbrainz@0.7.0                - Musicbrainz client library
p plcairo@1.1.1                    - plcairo - Prolog bindings for cairo graphics library
p prolog_graphviz@1.0.5            - Prolog-based graph visualization
p pub_graph@1.2                    - Access, cache and visualise citation relations in publications servers
p sindice@0.0.5                    - Access to Sindice semantic web search engine
p sourcehut@0.1.10                 - SourceHut GraphQL API client
p wgraph@0.6                       - Weighted graphs, with plotting via Real
true.
1 Like