Skip to content

InternetSocket: Cant reuse an object if open on IPStack fails #14825

Open
@LukasKarel

Description

@LukasKarel

Description of defect

If a socket should be opened but the stack cant open it, there is no possibility to retry opening it later again. The stack is saved even if the socket cant be opened on the stack. Which lead to a problem because of the if statement on line 38. Another call on open is not possible because the stack is saved internally but cant be reset.

nsapi_error_t InternetSocket::open(NetworkStack *stack)
{
_lock.lock();
if (_stack != NULL || stack == NULL) {
_lock.unlock();
return NSAPI_ERROR_PARAMETER;
}
_stack = stack;
nsapi_socket_t socket;
nsapi_error_t err = _stack->socket_open(&socket, get_proto());
if (err) {
_lock.unlock();
return err;
}

The close method does check if a socket is valid. If it is not, the stack is not removed from the InternetSocket.

nsapi_error_t InternetSocket::close()
{
_lock.lock();
nsapi_error_t ret = NSAPI_ERROR_OK;
if (!_socket) {
_lock.unlock();
return NSAPI_ERROR_NO_SOCKET;
}

Either the open method should remove the stack from the InternetSocket if the socket cant be opened, or the close method removes the stack from the InternetSocket even if the socket is not valid.

Target(s) affected by this defect ?

All.

Toolchain(s) (name and version) displaying this defect ?

All.

What version of Mbed-os are you using (tag or sha) ?

cecc47b

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

All.

How is this defect reproduced ?

Open as much sockets as available by the LWIPStack. Try open one extra socket. Close all other sockets. Try to open that extra socket again. Opening this socket wont be possible.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions