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

unit_tests.sh fails in last check with timeouted server connection #791

Open
ghorwin opened this issue Jan 20, 2025 · 1 comment · May be fixed by #792
Open

unit_tests.sh fails in last check with timeouted server connection #791

ghorwin opened this issue Jan 20, 2025 · 1 comment · May be fixed by #792

Comments

@ghorwin
Copy link
Contributor

ghorwin commented Jan 20, 2025

Running unit_tests.sh gives an assert in the unit-test-client.log:

...
7/8 Disable byte timeout: OK
8/8 Connection timeout: 
Line 679: assertion error for 'rc == -1 && (*__errno_location ()) == 110': 

This causes the test suite to fail.

@ghorwin
Copy link
Contributor Author

ghorwin commented Jan 20, 2025

Regression was introduced in 6ae4a76

   // Invalid in TCP or RTU mode...
    modbus_t *invalid_ctx = modbus_new_tcp("1.2.3.4", 1502);
    modbus_set_response_timeout(ctx, 0, 1);     // <-- BUG: should be invalid_ctx, right?
    rc = modbus_connect(invalid_ctx);
    printf("8/8 Connection timeout: ");
    ASSERT_TRUE(rc == -1 && errno == ETIMEDOUT, "");
    modbus_free(invalid_ctx);

When adjusting the response timeout in ctx rather the intendet invalid_ctx the connection fails with errno 111 (connection refused).

I'm not quite clear why this happens, as we try to use invalid_ctx in the connect statement and not ctx. The errno is set to ETIMEDOUT in modbus-tcp.c:310 correctly, when using the timeout on invalid_ctx. However, when we do not set the timeout, then the errno is set to ECONNREFUSED in modbus-tcp.c:319.

By changing ctx to invalid_ctx in the test code (see snipped above) the test suite runs correctly again. -> pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant