Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7068687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:21:16+00:00 2026-05-28T05:21:16+00:00

Good day, I have a gen_server process which does some long-running state-updating tasks periodically

  • 0

Good day,

I have a gen_server process which does some long-running state-updating tasks periodically in
handle_info:

handle_info(trigger, State) ->
    NewState = some_long_running_task(),
    erlang:send_after(?LOOP_TIME, self(), trigger),
    {noreply, NewState}.

But when such task runs, then whole server gets unresponsive and any call to it leads to whole server crash:

my_gen_server:status().
** exception exit: {timeout,{gen_server,call,[my_gen_server,status]}}
     in function  gen_server:call/2

How it is possible to avoid blocking of gen_server ?
And when one call my_gen_server:status() at any time, the result should be something like:
{ok, task_active}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:21:16+00:00Added an answer on May 28, 2026 at 5:21 am

    execute the long running task in a separate process. Let this process inform the gen_server of its progress with the task (that is if the task’s progress can be tracked) OR let the process complete the task or fail but at least inform the gen_server of the results of the task.

    Let the gen_server be linked with the process doing this long running task, and let the gen_server know the PID or registered name so that in case of exit signals, it can isolate the death of that important process from the Rest.

    handle_info(trigger, State) ->
        Pid = spawn_link(?MODULE,some_long_running_task,[State]),
        NewState = save_pid(Pid,State),
        {noreply, NewState};
    handle_info({'EXIT',SomePid,_},State)->
        case lookup_pid(State) == SomePid of
            false -> %% some other process
                {noreply,State};
            true ->
                %% our process has died
                %% what do we do now ?
                %% spawn another one ?
                %% thats your decision to take
                ....
                ....
                {noreply,State}
        end;
    handle_info({finished,TaskResult},State)->
        .....%% update state e.t.c.
        erlang:send_after(?LOOP_TIME, self(), trigger),
        {noreply,NewState}.
    
    some_long_running_task(ServerState)->
        ....do work
        ....return results
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, If I have for example the documents which have the following fields
Good day members, I have an input file which has rows of numerical digits
Good day, I have an activity which i navigate to from an icon on
Good day, I have run into some problem in the Zend_Cache_Frontend_Page. I want to
Good day, I have a hibernate mapping which goes something like this <class name=Person>
Good Day! I have a photostudio site running on a Wordpress. It's have a
Good day to all. I have this structure <html> <iframe> <div id=idd>Some Content</div> </iframe>
good day we are developing game for android and have some trouble with resource
Good day everyone, I have a directory set up with some Apache Auth stuff.
Good day! I have an application where I need to display and process a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.