Azure / Azure/azure-functions-host

Worker recycle takes a long time for a dedicated java function app

Open
#7,347 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

The function host / worker process takes a very long time to recycle when the following set of conditions are true.

1. It is a java function app
2. Function app is hosted of azure
3. Function app is hosted on (dedicated) app service plan
4. Function app has a long running timer trigger with blocking thread. (See sample code below)
5. A deployment is triggered via zip deploy call while the long running timer trigger is executing.
6. Function timeout is set to a long period. (more than 10 mins). It worse of with longer duration.

Repro steps:
1. Create a java function app on azure
2. Create a deploy the function app with the following sample code
``` Java
public class JavaSleep {
/**
* This function will be invoked periodically according to the specified schedule.
*/
@FunctionName("timerSleep")
public void justsleep(
@TimerTrigger(name = "javasleep", schedule = "0 20,50 0-23 * * *") String timerInfo,
final ExecutionContext context) throws Exception {
context.getLogger().info("TimerTrigger is invoded.");

try {
context.getLogger().info("start sleep in java.");
Thread.sleep(29 * 60 * 1000); // 29 min
context.getLogger().info("sleep done in java...");
} catch (Exception ex) {
context.getLogger().log(Level.SEVERE, ex.getMessage());
throw ex;
}

return ;
}
}
```
3. Deployment is triggered while the timer trigger execution is in progress using `mvn azure-functions:deploy`

Expected
- When deployment is triggered the function host should recycle, function host should load updated content and continue functioning.

Actual
- Function host recycle process does not complete.
- All http request including `host status` and `sync trigger` return 500 or 502

Known Workaround
- Steps to generate zip file
1. Run `mvn clean package` from the root of the function app
2. Navigate to `target -> azure-functions -> {function app name}`
3. Run `func pack` to generate the zip file
4. Upload the zip file to storage account, generate the sas token to download the zip file
- Set the function app setting `WEBSITE_RUN_FROM_PACKAGE={SAS url that points to zip file that contains function app content}`

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the Java timer sample on a dedicated Azure App Service plan, using a long-running blocking trigger and deploying with mvn azure-functions:deploy. Observe the function host recycle along with host status and sync trigger responses. Done means deployment completes, the host loads the updated content, and those requests no longer return 500 or 502.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, java
Domain
backend, cloud
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.