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

When errors occurs, iperf_run_client exits instead of returning #1205

Closed
dk1301 opened this issue Sep 17, 2021 · 1 comment · Fixed by #1209
Closed

When errors occurs, iperf_run_client exits instead of returning #1205

dk1301 opened this issue Sep 17, 2021 · 1 comment · Fixed by #1209
Assignees
Labels

Comments

@dk1301
Copy link

dk1301 commented Sep 17, 2021

NOTE: The iperf3 issue tracker is for registering bugs, enhancement
requests, or submissions of code. It is not a means for asking
questions about building or using iperf3. Those are best directed
towards the iperf3 mailing list at iperf-dev@googlegroups.com or
question sites such as Stack Overflow
(http://www.stackoverflow.com/). A list of frequently-asked questions
regarding iperf3 can be found at http://software.es.net/iperf/faq.html.

Context

  • Version of iperf3:3.10.1

  • Hardware: Intel(R) Core(TM) i5-6300U CPU

  • Operating system (and distribution, if any): Vm Ubuntu 16.04

Please note: iperf3 is supported on Linux, FreeBSD, and macOS.
Support may be provided on a best-effort basis to other UNIX-like
platforms. We cannot provide support for building and/or running
iperf3 on Windows, iOS, or Android.

  • Other relevant information (for example, non-default compilers,
    libraries, cross-compiling, etc.):

Please fill out one of the "Bug Report" or "Enhancement Request"
sections, as appropriate.

Bug Report

I compiled the misc.c example of libiperf

#include "iperf_config.h"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif

#include <iperf_api.h>


int
main( int argc, char** argv )
{
    char* argv0;
    char* host;
    int port;
    struct iperf_test *test;

    argv0 = strrchr( argv[0], '/' );
    if ( argv0 != (char*) 0 )
	++argv0;
    else
	argv0 = argv[0];

    if ( argc != 3 ) {
	fprintf( stderr, "usage: %s [host] [port]\n", argv0 );
	exit( EXIT_FAILURE );
    }
    host = argv[1];
    port = atoi( argv[2] );

    test = iperf_new_test();
    if ( test == NULL ) {
	fprintf( stderr, "%s: failed to create test\n", argv0 );
	exit( EXIT_FAILURE );
    }
    iperf_defaults( test );
    iperf_set_verbose( test, 1 );

    iperf_set_test_role( test, 'c' );
    iperf_set_test_server_hostname( test, host );
    iperf_set_test_server_port( test, port );
    /* iperf_set_test_reverse( test, 1 ); */
    iperf_set_test_omit( test, 3 );
    iperf_set_test_duration( test, 5 );
    iperf_set_test_reporter_interval( test, 1 );
    iperf_set_test_stats_interval( test, 1 );
    /* iperf_set_test_json_output( test, 1 ); */

    if ( iperf_run_client( test ) < 0 ) {
	fprintf( stderr, "%s: error - %s\n", argv0, iperf_strerror( i_errno ) );
	exit( EXIT_FAILURE );
    }

    if (iperf_get_test_json_output_string(test)) {
	fprintf(iperf_get_test_outfile(test), "%zd bytes of JSON emitted\n",
		strlen(iperf_get_test_json_output_string(test)));
    }

    iperf_free_test( test );
    exit( EXIT_SUCCESS );
}

Then I run the binary on purpose with erroneous host so as to check the code

  if ( iperf_run_client( test ) < 0 ) {
	fprintf( stderr, "%s: error - %s\n", argv0, iperf_strerror( i_errno ) );
	exit( EXIT_FAILURE );
    }

But the program never passes the if ( iperf_run_client( test ) < 0 ) line and exits with printout

iperf3: error - unable to connect to server: Name or service not known
I also put the code inside a try catch but there was no difference.
The same happens when the connection is rejected.

Since it's crucial for my app to handle the errors what else can I do ?

  • Expected Behavior
    I assumed that the code inside the above if will be executed.

  • Actual Behavior
    The code exits just after the if ( iperf_run_client( test ) < 0 ) line

  • Steps to Reproduce

./binary speedtest 5209 -> for the wrong host case

./binary iperf.par2.as49434.net 9200 -> for the connection refused case

  • Possible Solution

Please submit patches or code changes as a pull request.

Enhancement Request

  • Current behavior

  • Desired behavior

  • Implementation notes

If submitting a proposed implementation of an enhancement request,
please use the pull request mechanism.

@dk1301 dk1301 changed the title When error occurs then the negative case of iperf_run_client function of libiperf is not executed When errors occurs then the negative case of iperf_run_client function of libiperf is not executed Sep 17, 2021
@bmah888 bmah888 changed the title When errors occurs then the negative case of iperf_run_client function of libiperf is not executed When errors occurs, iperf_run_client exits instead of returning Sep 17, 2021
@bmah888 bmah888 added the bug label Sep 17, 2021
@bmah888
Copy link
Contributor

bmah888 commented Sep 17, 2021

PR #1202 appears relevant to this bug.

@swlars swlars self-assigned this Sep 25, 2021
@swlars swlars linked a pull request Sep 25, 2021 that will close this issue
@swlars swlars closed this as completed Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants