Skip to content

Commit

Permalink
Fix initialization problem under high load and enable test
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Jan 18, 2025
1 parent 53ce7e2 commit e4eea8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ jobs:
run: |
export RELEASE_VERSION="$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)"
echo $RELEASE_VERSION
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Dtest=ConsoleAppRestServiceTest#testRestartServerUnderHttpLoad -Dmaven.javadoc.skip=true --quiet
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Dtest=*/integration/* -Dmaven.javadoc.skip=true --quiet

- name: Show Ant Media Server Error Log on failure
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/io/antmedia/valves/DataTransferValve.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ValveBase;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -25,6 +27,9 @@
*
*/
public class DataTransferValve extends ValveBase {


private Logger logger = LoggerFactory.getLogger(DataTransferValve.class);

@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
Expand All @@ -36,6 +41,14 @@ public void invoke(Request request, Response response) throws IOException, Servl

if (StringUtils.isNotBlank(streamId) && (HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method)))
{

ConfigurableWebApplicationContext context = (ConfigurableWebApplicationContext) request.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

if (context == null || !context.isRunning()) {
logger.debug("Context is not ready yet for request: {}", request.getRequestURI());
return;
}

String subscriberId = ((HttpServletRequest) request).getParameter("subscriberId");

if (subscriberId != null) {
Expand All @@ -46,7 +59,6 @@ public void invoke(Request request, Response response) throws IOException, Servl

long bytesWritten = response.getBytesWritten(false);

ConfigurableWebApplicationContext context = (ConfigurableWebApplicationContext) request.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

PlayerStatsEvent playerStatsEvent = new PlayerStatsEvent();
playerStatsEvent.setStreamId(streamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public void run() {

i++;

if (i % 1000 == 0) {
if (i % 200 == 0) {
log.info("{} requests are sent to url", i, url);
}

Expand Down Expand Up @@ -491,7 +491,7 @@ public void run() {
}
}
else {
log.info("applications length is not {}: {}", appCount, applications.applications);
log.info("applications length is not {}: {}", appCount, applicationsTmp.applications);
}

return false;
Expand Down

0 comments on commit e4eea8c

Please sign in to comment.