LWIP_ASSERT on connect

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LWIP_ASSERT on connect

569 Views
biafra
Senior Contributor I
Hi everyone,
 
I'm working on a custom board using RT1064, MCUXpresso 11.8.1 and SDK 2.12.0.
 
I have a strange issue on lwip connect() function. There are multiple tasks using lwip functions, here are the concepts.
 
The server task waits for a connection and launch the session task (launched at startup):

 

void ServerTask( void )
{
    ...
    while( 1 )
    {
        sock1 = socket( ... );
        bind( sock1, ... );
        listen( sock1, ... );
        while( 1 )
        {
            sock2 = accept( sock1, ... )
            if( sock2 < 0 )
                break;
            xTaskCreate( SessionTask, ..., sock2, ... );
        }
        shutdown( sock1, SHUT_RDWR ));
        closesocket( sock1 );
    }
}

 

 
The session task process the protocol (launched when the server task receives a connection):

 

void SessionTask( int sock3 )
{
    ...
    while( 1 )
    {
        recv( sock3, ... );
        ... //process the protocol
        send( sock3, ... );

        if(( IsError1 != 0 ) || ( NeedToTerminate1 != 0 ))
            break;
    }
    shutdown( sock3, SHUT_RDWR ));
    closesocket( sock3 );

    vTaskDelete( NULL );
}

 

 
The terminal task sends messages to the debug client (launched at startup):

 

void TerminalTask( void )
{
    ...
    while( 1 )
    {
        sock4 = socket( ... );
        bind( sock4, ... );
        listen( sock4, ... );
        while( 1 )
        {
            sock5 = accept( sock4, ... )
            if( sock5 < 0 )
                break;
            ... //sends debug messages on sock4 until the client is connected
        }
        shutdown( sock4, SHUT_RDWR ));
        closesocket( sock4 );
    }
}

 

 
The notification task send some information to a remote server (launched at startup):

 

void NotificationTask( void )
{
    ...
    while( 1 )
    {
        sock6 = socket( ... );
        if( connect( sock6, ... ) != 0 )
        {
            closesocket( sock6 );
            ... //delay 10 s
            continue;
        }
        while( 1 )
        {
            send( sock6, ... );
            ... //process the protocol
            recv( sock6, ... );

            if(( IsError2 != 0 ) || ( NeedToTerminate2 != 0 ))
                break;
        }
        closesocket( sock6 );
    }
}

 

 
The behaviour is the following:
 
At startup tasks ServerTask, TerminalTask and NotificationTask are launched.

 

xTaskCreate( ServerTask, ... );
xTaskCreate( TerminalTask, ... );
xTaskCreate( NotificationTask, ... );

 

 
If the remote server is available and reachable from the notification task there is no issue.
 
The problem arises if the remote server is unavailable or not reachable from the notification task. In this case the notification task continuously tries to connect to the remote server, waiting 10 seconds between one attempt and the next.
If I connect from a client to the server task, I can modify the working configuration. 10 seconds after changing the configuration, the notification task is closed and restarted, and the sock6 socket is closed, if needed.

 

vTaskDelete( NotificationTaskHandle );
if( sock6_IsValid )
    closesocket( sock6 );
xTaskCreate( NotificationTask, ... );

 

 
After restarted, the first time notification task calls the connect() function, at the end of the connection attempt, I receive a LWIP_ASSERT() in the lwip_netconn_do_connect() function (file api_msg.c, line 1400, the second LWIP_ASSERT in the code below).

 

LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT);
UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT);

 

 
Why the problem arises? And why it arises only after I modified the configuration?
Where can be the coding error?
 
Many thanks
Biafra

 

Labels (1)
0 Replies