# Pack operations fail after upgrading swi-prolog to 9.2.1

**URL:** <https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247>\
**Category:** Pack\
**Created:** [February 16, 2024, 11:13pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247 "2024-02-16T23:13:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinwoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jinwoo/32/5745_2.png) [@jinwoo](https://swi-prolog.discourse.group/u/jinwoo)\
**Post date:** [February 16, 2024, 11:13pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/1 "2024-02-16T23:13:10Z")

</div>

I reported [`pack` operations fail with `close_range` · Issue #164 · SWI-Prolog/packages-http · GitHub](https://github.com/SWI-Prolog/packages-http/issues/164) 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](https://github.com/SWI-Prolog/packages-http/commit/1e70298fb9ee14dc1c2cfb6663c47f84c83ed838).

The trace looks like this:

```prolog
?- 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)

```

---

<div class="post-metadata">

**Author:** ![anniepoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/anniepoo/32/12_2.png) [@anniepoo](https://swi-prolog.discourse.group/u/anniepoo)\
**Post date:** [February 17, 2024, 11:40am UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/2 "2024-02-17T11:40:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anniepoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/anniepoo/32/12_2.png) [@anniepoo](https://swi-prolog.discourse.group/u/anniepoo)\
**Post date:** [February 17, 2024, 12:13pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/3 "2024-02-17T12:13:48Z")

</div>

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](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](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.

---

<div class="post-metadata">

**Author:** ![jinwoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jinwoo/32/5745_2.png) [@jinwoo](https://swi-prolog.discourse.group/u/jinwoo)\
**Post date:** [February 17, 2024, 4:35pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/4 "2024-02-17T16:35:59Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 18, 2024, 6:02pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/6 "2024-02-18T18:02:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jinwoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jinwoo/32/5745_2.png) [@jinwoo](https://swi-prolog.discourse.group/u/jinwoo)\
**Post date:** [February 18, 2024, 7:10pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/7 "2024-02-18T19:10:51Z")

</div>

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](https://www.swi-prolog.org/download/stable).

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](http://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](http://swi-prolog.org). Still the same… Sigh…

---

<div class="post-metadata">

**Author:** ![jinwoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jinwoo/32/5745_2.png) [@jinwoo](https://swi-prolog.discourse.group/u/jinwoo)\
**Post date:** [February 18, 2024, 7:19pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/8 "2024-02-18T19:19:52Z")

</div>

I notice one thing weird in the stack trace.

```prolog
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.

---

<div class="post-metadata">

**Author:** ![jinwoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jinwoo/32/5745_2.png) [@jinwoo](https://swi-prolog.discourse.group/u/jinwoo)\
**Post date:** [February 18, 2024, 7:26pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/9 "2024-02-18T19:26:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 19, 2024, 8:13am UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/10 "2024-02-19T08:13:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 19, 2024, 8:39am UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/11 "2024-02-19T08:39:27Z")

</div>

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 ☹ 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.

---

<div class="post-metadata">

**Author:** ![jinwoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jinwoo/32/5745_2.png) [@jinwoo](https://swi-prolog.discourse.group/u/jinwoo)\
**Post date:** [February 19, 2024, 4:44pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/12 "2024-02-19T16:44:03Z")

</div>

Awesome. Thanks for the quick fix, Jan!

---

<div class="post-metadata">

**Author:** ![jinwoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jinwoo/32/5745_2.png) [@jinwoo](https://swi-prolog.discourse.group/u/jinwoo)\
**Post date:** [February 19, 2024, 5:04pm UTC](https://swi-prolog.discourse.group/t/pack-operations-fail-after-upgrading-swi-prolog-to-9-2-1/7247/13 "2024-02-19T17:04:52Z")

</div>

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

```prolog
~ % 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.

```
