# Swi-prolog 9.2.2 fails http:proxy test on armv7

**URL:** <https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275>\
**Category:** Installing\
**Tags:** bug\
**Created:** [March 3, 2024, 10:07pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275 "2024-03-03T22:07:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [March 3, 2024, 10:07pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275/1 "2024-03-03T22:07:16Z")

</div>

Hi, swi-prolog 9.2.2 has 1 test failure, with armv7, on Alpine Linux:

```prolog
45/82 Test #52: http:proxy .......................***Failed 1.39 sec

```

```prolog
% [10/13] proxy:Request URL..ections go via HTTP .. **FAILED (0.031 sec)
ERROR: /builds/brebs/aports/testing/swi-prolog/src/swipl-9.2.2/packages/http/test_proxy.pl:586:
ERROR: test proxy:'Request URL when all connections go via HTTP': received error: Unknown error term: proxy_error(tried([error(proxy(localhost,40817),error(socket_error(econnrefused,'Connection refused'),_15396))-[]]))
% Started server at http://localhost:33337/
% Started server at https://localhost:33543/
Warning: Unknown message: stop(http_proxy_server,error(socket_error(econnrefused,'Connection refused'),_16882))

```

Full output:

> **[build-armv7 (#1292586) · Jobs · Paul Bredbury / aports · GitLab](https://gitlab.alpinelinux.org/brebs/aports/-/jobs/1292586#L3719)**
>
> Alpine packages build scripts

Only armv7 has this problem (can be seen by clicking on the red cross, and seeing the successful builds in the drop-down list that appears):

> **[testing/swi-prolog: upgrade to 9.2.2 (!61598) · Merge requests · alpine /...](https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/61598)**
>
> Alpine packages build scripts

The tests [passed in swi-prolog 9.2.1](https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/60929)

Hopefully there’s an easy fix?

A [rerun succeeded](https://gitlab.alpinelinux.org/brebs/aports/-/jobs/1292599#L3726), so I’m unsure if the test is unstable on armv7, or perhaps the Alpine build server itself was unstable.

---

<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:** [March 4, 2024, 8:23am UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275/2 "2024-03-04T08:23:07Z")

</div>

That is still an open issue. The same happens on MacOS/M1 incidentally. I _think_ the issue is about reusing TCP/IP ports the wrong way while the various HTTP tests run concurrently, picking free ports to do the test. One of the tests gets 4 ports, then closes them and reuses them with explicit port numbers. Concurrent tests may pick these ports as free ports.

I’m not 100% sure though as these are two incidents on arm chips while I’m not aware of the issue on amd64/Linux. I expected the difference to be due to timing and port lingering on MacOS vs Linux, but this adds another data point to it.

So, I fear it needs to be resolved ☹

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [March 4, 2024, 2:05pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275/3 "2024-03-04T14:05:06Z")

</div>

> [@jan](#):
>
> Concurrent tests may pick these ports as free ports

Yes - the code is [free\_ports](https://github.com/SWI-Prolog/packages-http/blob/8e877c476d26066129a83df855ef25b33f546d5f/test_proxy.pl#L61)

`free_ports` should not exist - it should be e.g. `start_http_proxy` which instantiates the `Port `variable, and runs `assertz(port(socks, Port))`.

That would then prevent the race condition.

Just wanted to mention this nice code:

```prolog
?- tcp_socket(Socket), tcp_bind(Socket, localhost:Port).
Socket = <socket>(0x55b76f16c260),
Port = 55917.

```

---

<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:** [March 4, 2024, 2:48pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275/4 "2024-03-04T14:48:21Z")

</div>

That is probably roughly what needs to happen. I don’t recall the exact history. I think the original code was written with hard-wired ports, which of course causes other conflicts. The test surely needs to be fixed. Whether or not that fixes the issue gets a little less certain after the problem also emerges on arm on Linux. Now the common factor is the arm chip rather than the OS.

If you can figure it out how to fix the test, please make a PR.

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [March 10, 2024, 10:05pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275/5 "2024-03-10T22:05:16Z")

</div>

PR raised: [Don't reuse original test port for HTTP proxy by brebs-gh · Pull Request #165 · SWI-Prolog/packages-http · GitHub](https://github.com/SWI-Prolog/packages-http/pull/165)

It makes the port for the HTTP proxy _dynamic_, leaving 4 static ports remaining.

It’s reliable on Linux amd64… are you able to test whether it improves reliability on Mac M1, @jan ?

Hopefully it’s a quick win - completely preventing static port reuse seems to be a bigger task of redesigning all the tests in `test_proxy.pl`

---

<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:** [March 11, 2024, 8:12am UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275/6 "2024-03-11T08:12:20Z")

</div>

> [@brebs](#):
>
> are you able to test whether it improves reliability on Mac M1, @jan ?

Unless I was just very lucky, it seems to do the trick on the M1 as well 🙂 Thanks!

The whole thing remains a bit complicated of course. Notably test the failure to connect to an unused port is probably hard to do reliably in an unknown environment ☹

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [March 11, 2024, 8:38am UTC](https://swi-prolog.discourse.group/t/swi-prolog-9-2-2-fails-http-proxy-test-on-armv7/7275/7 "2024-03-11T08:38:02Z")

</div>

> [@jan](#):
>
> Notably test the failure to connect to an unused port

Yes - I don’t think there’s a properly-safe way to do that, especially as a non-root user.

I suppose we’re also testing the limits of [SO\_REUSEADDR](https://man7.org/linux/man-pages/man7/socket.7.html) 😀
