Netconn crushes after 10 minuts

Maybe my question will be to the wrong address
I have got some problem with my tcp ip
All works fine but not too long
I send data from STM32 to PC every 1 sec and after 10 minuts it goes to
configASSERT( pxQueue->uxItemSize == 0 ); - stopping after 10 minuts of working via TCP transfer
and stack analyzer shows what Im runnning Ethf task which I didnt find in sources
My code is:

// init //
/* Definitions for networkInit */
osThreadId_t networkInitHandle;
const osThreadAttr_t networkInit_attributes = {
  .name = "networkInit",
  .stack_size = 256 * 8,//384 * 4,
  .priority = (osPriority_t)  osPriorityHigh,

/* Definitions for TCPProc */
osThreadId_t TCPProcHandle;
const osThreadAttr_t TCPProc_attributes = {
  .name = "TCPProc",
  .stack_size = 256 * 8,//384 * 10,//8,//4,
  .priority = (osPriority_t) osPriorityNormal,

/* Definitions for TCPTx */
osThreadId_t TCPTxHandle;
const osThreadAttr_t TCPTx_attributes = {
  .name = "TCPTx",
  .stack_size = 256 * 8,//384 * 12,//128 * 4,
  .priority = (osPriority_t) osPriorityNormal,

/* Definitions for TCPip */
osThreadId_t mtcpConHandle;
const osThreadAttr_t mtcpCon_attributes = {
  .name = "mtcpCon",
  .stack_size = 256 * 8, //384 * 4,
  .priority = (osPriority_t) osPriorityNormal,

/* Definitions for quTCP */
osMessageQueueId_t quTCPHandle;
const osMessageQueueAttr_t quTCP_attributes = {
  .name = "quTCP"
void mstartTcpCon(void *argument);
void startNetworkInit(void *argument);
void startTCPProc(void *argument);
void startTCPTx(void *argument);
  //osMessageQueueId_t qu = quMsgM3gHandle;
  quTCPHandle = osMessageQueueNew (16, sizeof(MessageNode), &quTCP_attributes);
  /* creation of networkInit */
  networkInitHandle = osThreadNew(startNetworkInit, NULL, &networkInit_attributes);
  /* creation of TCPip connection*/
  mtcpConHandle = osThreadNew(mstartTcpCon, NULL, &mtcpCon_attributes);
// buffer for queues //
#define BUFFER_SIZE 11264
#define Middle_BUFFER_SIZE 1024
typedef struct MessageNode_
  char* message;//
  size_t size;
} MessageNode;

// threads //
void startNetworkInit(void *argument)
  /* init code for LWIP */

  /* Infinite loop */
  /* USER CODE END 5 */

/* USER CODE BEGIN Header_startTcpConnet */
void mstartTcpCon(void *argument)
	ip_addr_t server_ip;
	ip_addr_t client_ip;

	    err_t err;
	    IP4_ADDR(&server_ip, 10, 10, 100, 100);
	    IP4_ADDR(&client_ip, 10, 10, 100, 99);
	    conn = netconn_new(NETCONN_TCP);

	    if (conn != NULL)

	    	err = netconn_bind(conn, &client_ip, 6401);
	    	if (err == ERR_OK)
	    		while(netconn_connect(conn, &server_ip, 6401) != ERR_OK);
			cont = 2;
			tcpstatus = 0x01;



void startTCPProc(void *argument)
	struct netbuf *buffer;
  char *data;

	  if (cont == 2)
		  	  buffer = netbuf_new();
					while ((netconn_err(conn) == ERR_OK) && (netconn_recv(conn, &buffer) == ERR_OK))

								if(netbuf_data(buffer, (void *)&data, &lenc)== ERR_OK)

									case 0x01:

										if(server_find_unnecessary_info((const char*)data, lenc)==servAuthOk)
											tcpstatus = 0x02;
											lenc = 0;

											//netconn_write(conn, Conted, sizeof(Conted), NETCONN_COPY);

									case 0x05:

										if(server_auth_recv(ppm_id_get(),(const char* ) data)==servAuthOk)
											tcpstatus = 0x06;
											//netconn_write(conn, Subd, sizeof(Subd), NETCONN_COPY);
											lenc = 0;
											///xTimerStart(tmrInitLTCHandle, portMAX_DELAY);
									case 0x07:


											MessageNode msgNode;

											msgNode.message = pvPortMalloc(lenc);
											memcpy(msgNode.message, data, lenc);

											msgNode.message[(size_t)lenc] = '\0';
											msgNode.size = lenc -1;//strlen(masf);//msgNode.size = lenc;//
											xQueueSendToBack(quMsgPpmHandle, &msgNode, portMAX_DELAY);

											tcpstatus = 0x08;
											msgNode.message = vPortFree;
											lenc = 0;


							while (netbuf_next(buffer) >= 0);




void startTCPTx(void *argument)
 static char Conted[] = "Ath OK\r\n";
 static char Subd[] = "Sub OK\r\n";
 osMessageQueueId_t qu = quTCPHandle;

	  MessageNode msgNode;
	 switch (tcpstatus)
		 case 0x02:
		 netconn_write(conn, Conted, sizeof(Conted), NETCONN_COPY);
		 tcpstatus = 0x03;
		 case 0x04:
		 xQueueReceive(qu, &msgNode, portMAX_DELAY);
		 netconn_write(conn, msgNode.message, msgNode.size, NETCONN_COPY);
		 tcpstatus = 0x05;
		 case 0x06:
		 netconn_write(conn, Subd, sizeof(Subd), NETCONN_COPY);
		 tcpstatus = 0x07;
		 logstatus = 0x03;
		 case 0x10:
	         while(uxQueueMessagesWaiting( qu )!= 0)
		 xQueueReceive(qu, &msgNode, portMAX_DELAY);
		 netconn_write(conn, msgNode.message, msgNode.size, NETCONN_COPY);
		 tcpstatus = 0x07;
		 logstatus = 0x03;


I use STM32F429 lwip + freertos and use netconn API
Please help, who knows

This is a fairly strong indication that either your implementation of the critical section is insufficient or your priorities are misconfigured. Do you run an ISR above max_syscall that illegally performs OS calls? Or use a non FromISR version in an ISR? Or do not run your service interrupt with lowest priority?

The assert is kind of typical for a memory corruption. This can be caused by various bugs. Some were mentioned by @RAc . Others are stack overflows or broken heap management like freeing buffers twice or trying to free buffers from stack (instead of heap) etc.
Search the forum for pxQueue->uxItemSize == 0 and you’ll find a couple of related posts.
Do you have stack overflow checking enabled ?
Also there are some problematic things in your code like no return value checking, obviously using task suspend/resume for task synchronization (which is error prone), using critical section around netconn_write (where I think it’s not needed), etc. worth to review and improve.

That does not sound correct. Have you searched in all your code-base (including the driver code)? Are you linking any compiled code?

Also, as mentioned by others, please enable stack overflow check and malloc failed check.


Thanks to all, I tried to check all recomendations
I decreased threads stack sizes and now Ive got 13 minutes !
I stoping here now

Seems that you just stopped the IDLE task while running normally. I wonder why just decreasing task stacks helped, though. However, no more crash nor assert - that‘s a step forward :+1:

Thanks for your replay!

I randomly found on RAM the following info while code was executed:

 LinkThr EthIf   ../LWIP/Target/ethernetif.c netif != NULL   Assertion "%s" failed at line %d in %s
 "*:<>?|    +,;=[]  люђMSDOS5.0 NO NAME    FAT32    NO NAME    FAT      IDLE    Tmr Svc TmrQ    ../Middlewares/Third_Party/LwIP/src/api/api_lib.c   freeing conn without freeing pcb    Assertion "%s" failed at line %d in %s
 conn has no recvmbox    conn->acceptmbox shouldn't exist    conn has no op_completed    netconn_getaddr: invalid conn   netconn_getaddr: invalid addr   netconn_getaddr: invalid port   netconn_bind: invalid conn  netconn_bind_if: invalid conn   netconn_connect: invalid conn   netconn_disconnect: invalid conn    netconn_listen: invalid conn    netconn_accept: invalid pointer netconn_accept: invalid conn    netconn_recv: invalid pointer   netconn_recv: invalid conn  buf != NULL netconn_recv_tcp_pbuf: invalid conn netconn_recv_udp_raw_netbuf: invalid conn   p != NULL   netconn_send: invalid conn  netconn_write: invalid conn netconn_write: invalid conn->type   do_write failed to write all bytes  netconn_close: invalid conn ../Middlewares/Third_Party/LwIP/src/api/api_msg.c   unhandled error Assertion "%s" failed at line %d in %s
 err != NULL recv_udp must have a pcb argument   recv_udp must have an argument  recv_udp: recv for wrong pcb!   recv_tcp must have a pcb argument   recv_tcp must have an argument  err != ERR_OK unhandled recv_tcp: recv for wrong pcb!   conn != NULL    conn->current_msg != NULL   inavlid op_completed_sem    conn->current_msg == NULL   expect newpcb == NULL or err == ERR_OK  pcb_new: pcb already allocated  netconn_alloc: undefined netconn_type   PCB must be deallocated outside this function   recvmbox must be deallocated before calling this function   acceptmbox must be deallocated before calling this function invalid conn    this is for tcp netconns only   conn must be in state NETCONN_CLOSE pcb already closed  Closing a listen pcb may not fail!  err != ERR_OK   netconn state error blocking connect in progress    already writing or closing  state!  conn->state == NETCONN_CONNECT  (conn->current_msg != NULL) || conn->in_non_blocking_connect    blocking connect state error    Invalid netconn type    conn->state == NETCONN_WRITE    conn->pcb.tcp != NULL   conn->current_msg->msg.w.offset < conn->current_msg->msg.w.len  conn->current_msg->msg.w.vector_cnt > 0 lwip_netconn_do_writemore: invalid length!  msg->msg.w.len != 0 invalid netconn_type    ../Middlewares/Third_Party/LwIP/src/api/netbuf.c    netbuf_alloc: invalid buf   Assertion "%s" failed at line %d in %s
 check that first pbuf can hold size netbuf_free: invalid buf    netbuf_ref: invalid buf netbuf_chain: invalid head  netbuf_chain: invalid tail  netbuf_data: invalid buf    netbuf_data: invalid dataptr    netbuf_data: invalid len    netbuf_next: invalid buf    netbuf_first: invalid buf   ../Middlewares/Third_Party/LwIP/src/api/tcpip.c tcpip_thread: invalid message   Assertion "%s" failed at line %d in %s
 Invalid mbox    failed to create tcpip_thread mbox  failed to create lock_tcpip_core    tcpip_thread    ../Middlewares/Third_Party/LwIP/src/core/mem.c  plug_holes: mem >= ram  Assertion "%s" failed at line %d in %s
 plug_holes: mem < ram_end   plug_holes: mem->used == 0  plug_holes: mem->next <= MEM_SIZE_ALIGNED   failed to create mem_mutex  mem_free: sanity check alignment    mem_free: illegal memory    mem_free: illegal memory: double free   mem_free: illegal memory: non-linked: double free   mem_trim: legal memory  mem_trim can only shrink memory invalid next ptr    mem_malloc: !lfree->used    mem_malloc: allocated memory not above ram_end. mem_malloc: allocated memory properly aligned.  mem_malloc: sanity check alignment  ../Middlewares/Third_Party/LwIP/src/core/memp.c memp_malloc: memp properly aligned  Assertion "%s" failed at line %d in %s
 invalid pool desc   memp_malloc: type < MEMP_MAX    memp_free: mem properly aligned memp_free: type < MEMP_MAX  ../Middlewares/Third_Party/LwIP/src/core/netif.c    netif_input: invalid pbuf   Assertion "%s" failed at line %d in %s
 netif_input: invalid netif  netif_add: invalid netif    netif_add: No init function given   netif already added too many netifs, max. supported number is 255   invalid pointer netif_set_ipaddr: invalid netif netif_set_netmask: invalid netif    netif_set_gw: invalid netif netif_set_up: invalid netif netif_issue_reports: invalid netif  netif_set_down: invalid netif   netif_set_link_up: invalid netif    netif_set_link_down: invalid netif  ../Middlewares/Third_Party/LwIP/src/core/pbuf.c pbuf_alloc: pbuf q->payload properly aligned    Assertion "%s" failed at line %d in %s
 PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT pbuf_alloc: pbuf->payload properly aligned  pbuf_alloc: erroneous type  invalid pbuf_type   pbuf_realloc: p != NULL pbuf_realloc: q != NULL mem_trim returned q == NULL p != NULL   increment_magnitude <= p->len   pbuf_free: p->ref > 0   pc->custom_free_function != NULL    invalid pbuf type   pbuf ref overflow   (h != NULL) && (t != NULL) (programmer violates API)    p->tot_len == p->len (of last pbuf in chain)    p->next == NULL p->tot_len == p->len + q->tot_len   p->tot_len == p->len    pbuf_copy: target not big enough to hold source offset_to <= p_to->len  offset_from <= p_from->len  p_to != NULL    pbuf_copy() does not allow packet queues!   pbuf_copy_partial: invalid buf  pbuf_copy_partial: invalid dataptr  pbuf_get_contiguous: invalid buf    pbuf_get_contiguous: invalid dataptr    pbuf_take: invalid buf  pbuf_take: invalid dataptr  pbuf_take: buf not large enough pbuf_take: invalid pbuf did not copy all data   check pbuf_skip result  pbuf_copy failed    CLOSED  LISTEN  SYN_SENT    SYN_RCVD    ESTABLISHED FIN_WAIT_1  FIN_WAIT_2  CLOSE_WAIT  CLOSING LAST_ACK    TIME_WAIT   ../Middlewares/Third_Party/LwIP/src/core/tcp.c  tcp_free: LISTEN    Assertion "%s" failed at line %d in %s
 tcp_free_listen: !LISTEN    tcp_remove_listener: invalid listener   pcb != NULL pcb->state == LISTEN    tcp_close_shutdown: invalid pcb pcb->flags & TF_RXCLOSED    tcp_close: invalid pcb  tcp_shutdown: invalid pcb   tcp_abandon: invalid pcb    don't call tcp_abort/tcp_abandon for listen-pcbs    tcp_bind: invalid pcb   tcp_bind: can only bind in state CLOSED tcp_accept_null: invalid pcb    tcp_listen_with_backlog_and_err: invalid pcb    tcp_listen_with_backlog_and_err: pcb already connected  tcp_update_rcv_ann_wnd: invalid pcb new_rcv_ann_wnd <= 0xffff   tcp_recved: invalid pcb don't call tcp_recved for listen-pcbs   tcp_connect: invalid pcb    tcp_connect: invalid ipaddr tcp_connect: can only connect from state CLOSED tcp_slowtmr: active pcb->state != CLOSED
   tcp_slowtmr: active pcb->state != LISTEN
   tcp_slowtmr: active pcb->state != TIME-WAIT
    tcp_slowtimr: persist ticking with in-flight data   tcp_slowtimr: persist ticking with empty send buffer    tcp_slowtmr: middle tcp != tcp_active_pcbs  tcp_slowtmr: first pcb == tcp_active_pcbs   tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT  tcp_slowtmr: middle tcp != tcp_tw_pcbs  tcp_slowtmr: first pcb == tcp_tw_pcbs   tcp_process_refused_data: invalid pcb   tcp_setprio: invalid pcb    tcp_seg_copy: invalid seg   tcp_recv_null: invalid pcb  invalid state   invalid socket state for recv callback  invalid socket state for sent callback  invalid socket state for err callback   tcp_poll: invalid pcb   invalid socket state for poll   tcp_pcb_purge: invalid pcb  tcp_pcb_remove: invalid pcb tcp_pcb_remove: invalid pcblist unsent segments leaking unacked segments leaking    ooseq segments leaking  tcp_next_iss: invalid pcb   tcp_eff_send_mss_netif: invalid dst_ip  tcp_netif_ip_addr_changed_pcblist: invalid old_addr ../Middlewares/Third_Party/LwIP/src/core/tcp_in.c   tcp_input: invalid pbuf Assertion "%s" failed at line %d in %s
 p->next != NULL p->len == 0 p->tot_len == p->next->tot_len  tcp_input: active pcb->state != CLOSED  tcp_input: active pcb->state != TIME-WAIT   tcp_input: active pcb->state != LISTEN  tcp_input: pcb->next != pcb (before cache)  tcp_input: pcb->next != pcb (after cache)   tcp_input: TIME-WAIT pcb->state == TIME-WAIT    pcb->refused_data == NULL   tcp_input_delayed_close: invalid pcb    tcp_listen_input: invalid pcb   tcp_timewait_input: invalid pcb tcp_process: invalid pcb    tcp_input: pcb->state != CLOSED pcb->snd_queuelen > 0   no segment to free  pcb->listener->accept != NULL   tcp_oos_insert_segment: invalid cseg    pcb->snd_queuelen >= pbuf_clen(next->p) tcp_receive: valid queue length tcp_receive: invalid pcb    tcp_receive: wrong state    unacked unsent  inseg.p != NULL insane offset!  pbuf too short! tcp_receive: segment not trimmed correctly to rcv_wnd
  tcp_receive: segment not trimmed correctly to ooseq queue
  tcp_receive: tcplen > rcv_wnd
  tcp_receive: ooseq tcplen > rcv_wnd
    tcp_parseopt: invalid pcb   ../Middlewares/Third_Party/LwIP/src/core/tcp_out.c  tcp_create_segment: invalid pcb Assertion "%s" failed at line %d in %s
 tcp_create_segment: invalid pbuf    p->tot_len >= optlen    tcp_pbuf_prealloc: invalid oversize tcp_pbuf_prealloc: invalid pcb  need unchained pbuf tcp_write_checks: invalid pcb   tcp_write: pbufs on queue => at least one queue non-empty   tcp_write: no pbufs on queue => both queues empty   tcp_write: invalid pcb  tcp_write: arg == NULL (programmer violates API)    mss_local is too small  inconsistent oversize vs. space inconsistent oversize vs. len   tcp_write: ROM pbufs cannot be oversized    unsent_oversize mismatch (pcb->unsent is NULL)  tcp_write: check that first pbuf can hold the complete seglen   oversize == 0   prev_seg != NULL    tcp_write: cannot concatenate when pcb->unsent is empty tcp_write: extension of reference requires reference    tcp_write: valid queue length   tcp_split_unsent_seg: invalid pcb   Can't split segment into length 0   split <= mss    useg->len > 0   seg == NULL tcp_send_fin: invalid pcb   tcp_enqueue_flags: need either TCP_SYN or TCP_FIN in flags (programmer violates API)    tcp_enqueue_flags: invalid pcb  tcp_enqueue_flags: check that first pbuf can hold optlen    seg->tcphdr not aligned tcp_enqueue_flags: invalid segment length   tcp_enqueue_flags: invalid queue length tcp_output: invalid pcb don't call tcp_output for listen-pcbs   RST not expected here!  tcp_output_segment_busy: invalid seg    tcp_output_segment: invalid seg tcp_output_segment: invalid pcb tcp_output_segment: invalid netif   options not filled  tcp_rexmit_rto_prepare: invalid pcb tcp_rexmit_rto_commit: invalid pcb  tcp_rexmit_rto: invalid pcb tcp_rexmit: invalid pcb tcp_rexmit_fast: invalid pcb    check that first pbuf can hold struct tcp_hdr   tcp_output_alloc_header: invalid pcb    tcp_output_fill_options: invalid pbuf   tcp_output_control_segment: invalid pbuf    tcp_rst: invalid local_ip   tcp_rst: invalid remote_ip  tcp_send_empty_ack: invalid pcb tcp_keepalive: invalid pcb  tcp_zero_window_probe: invalid pcb  ../Middlewares/Third_Party/LwIP/src/core/timeouts.c sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty    Assertion "%s" failed at line %d in %s
 Timeout time too long, max is LWIP_UINT32_MAX/4 msecs   invalid sleeptime   ../Middlewares/Third_Party/LwIP/src/core/udp.c  udp_input_local_match: invalid pcb  Assertion "%s" failed at line %d in %s
 udp_input_local_match: invalid netif    udp_input: invalid pbuf udp_input: invalid netif    pbuf_remove_header failed
  udp_send: invalid pcb   udp_send: invalid pbuf  udp_sendto: invalid pcb udp_sendto: invalid pbuf    udp_sendto: invalid dst_ip  udp_sendto_if: invalid pcb  udp_sendto_if: invalid pbuf udp_sendto_if: invalid dst_ip   udp_sendto_if: invalid netif    udp_sendto_if_src: invalid pcb  udp_sendto_if_src: invalid pbuf udp_sendto_if_src: invalid dst_ip   udp_sendto_if_src: invalid src_ip   udp_sendto_if_src: invalid netif    check that first pbuf can hold struct udp_hdr   udp_bind: invalid pcb   udp_connect: invalid pcb    udp_connect: invalid ipaddr udp_disconnect: invalid pcb udp_recv: invalid pcb   udp_remove: invalid pcb ../Middlewares/Third_Party/LwIP/src/core/ipv4/dhcp.c    dhcp_inc_pcb_refcount(): memory leak    Assertion "%s" failed at line %d in %s
 dhcp_pcb_refcount(): refcount error dhcp_select: netif != NULL  dhcp_select: dhcp != NULL   netif != NULL   dhcp != NULL    netif already has a struct dhcp set netif is not up, old style port?    invalid dhcp->state dhcp_bind: netif != NULL    dhcp_bind: dhcp != NULL dhcp_option: options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN   dhcp_option_byte: options_out_len < DHCP_OPTIONS_LEN    dhcp_option_short: options_out_len + 2 <= DHCP_OPTIONS_LEN  dhcp_option_long: options_out_len + 4 <= DHCP_OPTIONS_LEN   len == 4    len >= decode_len   len == 1    overload in file/sname  check decode_idx    decode_len %% 4 == 0    invalid decode_len  next pbuf was null  dhcp_create_msg: netif != NULL  dhcp_create_msg: dhcp != NULL   dhcp_create_msg: check that first pbuf can hold struct dhcp_msg ../Middlewares/Third_Party/LwIP/src/core/ipv4/etharp.c  state == ETHARP_STATE_PENDING || state >= ETHARP_STATE_STABLE   Assertion "%s" failed at line %d in %s
 arp_table[i].q == NULL  i < ARP_TABLE_SIZE  arp_table[i].state == ETHARP_STATE_EMPTY    netif->hwaddr_len == ETH_HWADDR_LEN eth_ret != NULL && ip_ret != NULL   ipaddr != NULL  netif != NULL   eth_ret != NULL arp_table[arp_idx].state >= ETHARP_STATE_STABLE q != NULL   type overflow   arp_table[i].state == PENDING or STABLE no packet queues allowed!   check that first pbuf can hold struct etharp_hdr    netif->hwaddr_len must be the same as ETH_HWADDR_LEN for etharp!    ../Middlewares/Third_Party/LwIP/src/core/ipv4/icmp.c    icmp_input: moving r->payload to icmp header failed
    Assertion "%s" failed at line %d in %s
 icmp_input: restoring original p->payload failed
   check that first pbuf can hold icmp message ../Middlewares/Third_Party/LwIP/src/core/ipv4/ip4.c p->ref == 1 Assertion "%s" failed at line %d in %s
 check that first pbuf can hold struct ip_hdr    ../Middlewares/Third_Party/LwIP/src/core/ipv4/ip4_frag.c    prev != ipr Assertion "%s" failed at line %d in %s
 prev->next == ipr   pbufs_freed + clen <= 0xffff    ip_reass_pbufcount >= pbufs_freed   sanity check linked list    check fragments don't overlap   no previous fragment, this must be the first fragment!  sanity check    validate_datagram:next_pbuf!=NULL   ip_reass_pbufcount >= clen  ipr != NULL not firstalthough just enqueued p != NULL   pcr != NULL pcr == p    ip4_frag(): pbuf too short  this needs a pbuf in one piece! p->len >= poff  ../Middlewares/Third_Party/LwIP/src/netif/ethernet.c    netif->hwaddr_len must be 6 for ethernet_output!    Assertion "%s" failed at line %d in %s

The problem is still exist

After that I in opt.h - #define TCP_MSS 2048//1024//536

But Its got nothing

your code is completly illegible. Please reformat.

sorry what code you have meant, which I posted at the topic?