Code stuck in flash_manager_wait() when writing in flash don't succeed

Hi,

I try to write in flash with the flash_manager. I use this code to write in the flash.

void flash_write(uint16_t id_data, uint32_t value[4] ){
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "in flash_write\n");
    fm_entry_t * p_entry = flash_manager_entry_alloc(&m_custom_data_flash_manager, id_data, sizeof(custom_data_format_t));
    if (p_entry == NULL)
    {
      return NRF_ERROR_BUSY;
    }
      else
    {
       
      custom_data_format_t * p_custom_data = (custom_data_format_t *) p_entry->data;
      p_custom_data->data[0] = value[0];
      p_custom_data->data[1] = value[1];
      p_custom_data->data[2] = value[2];
      p_custom_data->data[3] = value[3];
   
      flash_manager_entry_commit(p_entry);
      __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "write:%x, %x, %x on %d \n",p_entry->data[0], p_entry->data[1], p_entry->data[2], id_data);
      
    }
    
    flash_manager_wait();
    
}

Everything is fine when the flash writing succeed. But when a issue occur in the flash manager (i don't know which issue), the code is stuck in the flash_manager_wait().
This method waits that the flash has finish and is clean before going on. here is the comment in the nordic code "Temporary hack to make sure that bearer events are handled while waiting for the flash manager to finish". (see code below)

static inline void flash_manager_wait(void)
{
#if !defined(HOST)
    while (!flash_manager_is_stable())
    {
        /* Temporary hack to make sure that bearer events are handled while waiting for
         * the flash manager to finish.
         * TODO: Find a solution for this that does not include busy-waiting. */
        if (bearer_event_handler())
        {
            __WFE();
        }
    }
#endif
}

Seeing the method, it is logical that we are stuck in this method if an issue occurs ... there is no timeout system or it does not return "False" for exemple if there is an error in the flash manager ... This is problematic since the only way is rebooting. I see that the nordic devs said in comment "* TODO: Find a solution for this that does not include busy-waiting. */"
It looks linked to my case.

Can you please say if if you have now a solution for this ?
Do I have to implement my self a kind of timeout with a counter ?
Can you advice me if I have to implement something myself to avoid my code to be stuck in case of an issue in the flash manager ?

Waiting for your answer !

Valentin

Related