Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Race condition in socket closing / address binding / DHCP

Posted by peku33 on August 10, 2016

Hi.

I'm using FreeRTOS 9.0 / Labs TCP project. I discovered a possibility of race condition in process of binding / releasing socket.

The main issue is, that under higher system loads, the DHCP tasks likes to call configASSERT( xReturn == 0 ); just after xReturn = vSocketBind( xDHCPData.xDHCPSocket, &xAddress, sizeof( xAddress ), pdFALSE );

After investigation i found this is because of Address in use problem.

This is (most likely) caused by delay between FreeRTOS_closesocket( xDHCPData.xDHCPSocket ); and actual freeing of bind in vSocketClose (which is delayed to task).

Before the port is released, the DHCP socket is recreated and bind fails causing assertion to kill the system.

While I'm able to understand why releasing buffers is delayed, I'm not able to get why removing of bind isn't done immediately.

Possible solution (but I'm not sure if there aren't any other constraints) is to move uxListRemove( &( pxSocket->xBoundSocketListItem ) ); to FreeRTOS_closesocket instead of vSocketClose.

Best regards, PaweĊ‚ Kubrak


Race condition in socket closing / address binding / DHCP

Posted by rtel on August 11, 2016

Thank you for your feedback - this will be investigated and reported back.


Race condition in socket closing / address binding / DHCP

Posted by heinbali01 on August 13, 2016

As the DHCP code always runs from within the IP-task, I think it is safe to call the internal close function vSocketClose().

~~~~ Public API Internal call

FreeRTOSclosesocket vSocketClose FreeRTOSbind vSocketBind ~~~~

Within FreeRTOS_DHCP.c, could you replace all occurrences of FreeRTOS_closesocket() with vSocketClose() and see if that helps?

I just tried that myself and it works fine for me.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists