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

Execution of io_test (bash_tests.testcases.TestCases) fails on Windows 11 #2781

Closed
norbertwg opened this issue Sep 24, 2023 · 10 comments · Fixed by #2803
Closed

Execution of io_test (bash_tests.testcases.TestCases) fails on Windows 11 #2781

norbertwg opened this issue Sep 24, 2023 · 10 comments · Fixed by #2803

Comments

@norbertwg
Copy link
Contributor

When I run the tests with python3 runner.py on my local Windows 11 system, it fails with io_test:

ERROR: io_test (bash_tests.testcases.TestCases)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\GitHub\norbertwg_exiv2\tests\bash_tests\testcases.py", line 595, in io_test
    out     += BT.Executer('iotest ' + ' '.join(files))
  File "C:\GitHub\norbertwg_exiv2\tests\bash_tests\utils.py", line 488, in __init__
    self.run()
  File "C:\GitHub\norbertwg_exiv2\tests\bash_tests\utils.py", line 527, in run
    raise RuntimeError('\n' + log.to_str())
RuntimeError:
[INFO] Starting HTTP server ...
[INFO] The HTTP server started
[ERROR] Failed to execute: C:\GitHub\norbertwg_exiv2\build\bin\iotest s0 s1 s2 http://127.0.0.1:12760/table.jpg
[ERROR] The asserted return code is [0], but got 1
[INFO] OUTPUT:
error - unable to connect to server = 127.0.0.1 port = 12760 wsa_error = 0
Caught Exiv2 exception 'http: Failed to open file (-1): /table.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\GitHub\norbertwg_exiv2\tests\bash_tests\testcases.py", line 605, in io_test
    raise RuntimeError('\n' + BT.log.to_str())
RuntimeError:
[INFO] Starting HTTP server ...
[INFO] The HTTP server started
[ERROR] Failed to execute: C:\GitHub\norbertwg_exiv2\build\bin\iotest s0 s1 s2 http://127.0.0.1:12760/table.jpg
[ERROR] The asserted return code is [0], but got 1
[INFO] OUTPUT:
error - unable to connect to server = 127.0.0.1 port = 12760 wsa_error = 0
Caught Exiv2 exception 'http: Failed to open file (-1): /table.jpg'
[ERROR]
[INFO] Starting HTTP server ...
[INFO] The HTTP server started
[ERROR] Failed to execute: C:\GitHub\norbertwg_exiv2\build\bin\iotest s0 s1 s2 http://127.0.0.1:12760/table.jpg
[ERROR] The asserted return code is [0], but got 1
[INFO] OUTPUT:
error - unable to connect to server = 127.0.0.1 port = 12760 wsa_error = 0
Caught Exiv2 exception 'http: Failed to open file (-1): /table.jpg'

This has a lower priority. As this error occurs even with the original sources from GitHub I ignore it when I test my changes. But I would like to understand it and avoiding this makes it more comfortable to verify my changes.

@neheb
Copy link
Collaborator

neheb commented Oct 13, 2023

I've frequently gotten this error. No real idea why. CI doesn't show it. Maybe firewall is interfering.

@norbertwg
Copy link
Contributor Author

@neheb thanks for the hint, but it's not firewall. It failed after disabling firewall completely.

I checked older versions. It worked with the release 0.28.0. It worked running iotest.exe from 0.28.0 with latest test scripts, but not vice versa. So it probably is a change in iotest.exe and I started to look for differences. Perhaps somebody with knowledge what iotest does, can give me a hint where to look at.

@norbertwg
Copy link
Contributor Author

I have now identified, with which change this problem appeared, it is e7f6a28
Using the http.cpp from commit before works fine for me with the latest sources.

@neheb : Do you have an idea, why this change causes iotest to fail on my local Windows 11 machine, whereas it works on GitHub test servers?

@neheb
Copy link
Collaborator

neheb commented Oct 17, 2023

Not at all.

edit: try running as Administrator

@norbertwg
Copy link
Contributor Author

Unfortunately, running as Administrator did not help.

@neheb
Copy link
Collaborator

neheb commented Oct 19, 2023

Can you try:

--- a/src/http.cpp
+++ b/src/http.cpp
@@ -226,7 +226,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
   server = connect(sockfd, reinterpret_cast<const sockaddr*>(&serv_addr), serv_len);
   if (server == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) {
     closesocket(sockfd);
-    return error(errors, "error - unable to connect to server = %s port = %s wsa_error = %d", servername_p, port_p,
+    return error(errors, "error - unable to connect to server = %s port = %s wsa_error = %d", servername_p, std::to_string(serv_addr.sin_port).c_str(),
                  WSAGetLastError());
   }
 

@norbertwg
Copy link
Contributor Author

I tried it, error is now:
error - unable to connect to server = 127.0.0.1 port = 0 wsa_error = 0
So instead of 12760 port shows 0.

What I found now: the code after calling inet_pton in line 205 is not executed, inet_pton returns 1. Looking on https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_pton and scrolling down to Return value, I found:

If no error occurs, the InetPton function returns a value of 1 and the buffer pointed to by the pAddrBuf parameter contains the binary numeric IP address in network byte order.

The InetPton function returns a value of 0 if the pAddrBuf parameter points to a string that is not a valid IPv4 dotted-decimal string or a valid IPv6 address string. Otherwise, a value of -1 is returned, and a specific error code can be retrieved by calling the
WSAGetLastError for extended error information.

As later in the code WSAGetLastError is checked, I tried != 0 instead of <= 0 - and test case completed successfully.

This was now try-and-error. I am not sure if this change can be the general solution.

@neheb
Copy link
Collaborator

neheb commented Oct 19, 2023

Sounds right. The commit ignores that section.

@norbertwg
Copy link
Contributor Author

If you agree, I will prepare a pull request, also including your change.

@neheb
Copy link
Collaborator

neheb commented Oct 19, 2023

Sure

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.

2 participants