elastic / apm-agent-java

https://www.elastic.co/guide/en/apm/agent/java/current/index.html
Apache License 2.0
567 stars 320 forks source link

give exception in jira 8.5.4 #1151

Closed vladimirshikhov closed 4 years ago

vladimirshikhov commented 4 years ago

Describe the bug

apm 1.15.0 jira 8.5.4 when the plugin is connected, and trying to add a user to the LDAP directory in the jira, the jira freezes

Steps to reproduce

1) plugin running with options: -javaagent:C:\elastic\elastic-apm-agent-1.15.0.jar -Delastic.apm.service_name=Jira_test_v8 -Delastic.apm.application_packages=org.example,org.another.example -Delastic.apm.server_urls=http://my-elastic:8200

2) create user in jira in delegated ldap directory

Debug logs

/secure/admin/user/AddUser.jspa [c.a.event.internal.AsynchronousAbleEventDispatcher] There was an exception thrown trying to dispatch event [com.atlassian.crowd.event.group.GroupMembershipsCreatedEvent@534a6b9e] from the invoker [SingleParameterMethodListenerInvoker{method=public void com.atlassian.jira.application.DefaultApplicationRoleManager.onGroupMembershipsCreated(com.atlassian.crowd.event.group.GroupMembershipsCreatedEvent), listener=com.atlassian.jira.application.DefaultApplicationRoleManager@7e9f38d}] java.lang.RuntimeException: co.elastic.apm.agent.impl.async.SpanInScopeRunnableWrapper cannot be cast to java.util.concurrent.Future. Listener:

Click to expand ``` /secure/admin/user/AddUser.jspa [c.a.event.internal.AsynchronousAbleEventDispatcher] There was an exception thrown trying to dispatch event [com.atlassian.crowd.event.group.GroupMembershipsCreatedEvent@534a6b9e] from the invoker [SingleParameterMethodListenerInvoker{method=public void com.atlassian.jira.application.DefaultApplicationRoleManager.onGroupMembershipsCreated(com.atlassian.crowd.event.group.GroupMembershipsCreatedEvent), listener=com.atlassian.jira.application.DefaultApplicationRoleManager@7e9f38d}] java.lang.RuntimeException: co.elastic.apm.agent.impl.async.SpanInScopeRunnableWrapper cannot be cast to java.util.concurrent.Future. Listener: com.atlassian.jira.application.DefaultApplicationRoleManager event: com.atlassian.crowd.event.group.GroupMembershipsCreatedEvent at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:57) at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.lambda$null$0(AsynchronousAbleEventDispatcher.java:37) at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:85) at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(EventPublisherImpl.java:227) at com.atlassian.event.internal.EventPublisherImpl.publish(EventPublisherImpl.java:112) at com.atlassian.crowd.manager.directory.DirectoryManagerGeneric.addUserToGroup(DirectoryManagerGeneric.java:636) at com.atlassian.crowd.manager.application.ApplicationServiceGeneric.addUserToGroup(ApplicationServiceGeneric.java:1026) at com.atlassian.crowd.embedded.core.CrowdServiceImpl.addUserToGroup(CrowdServiceImpl.java:543) at com.atlassian.jira.user.util.UserUtilImpl.doAddUserToGroup(UserUtilImpl.java:359) at com.atlassian.jira.user.util.UserUtilImpl.addUserToGroups(UserUtilImpl.java:373) at com.atlassian.jira.bc.user.DefaultUserService.createUser(DefaultUserService.java:289) at com.atlassian.jira.web.action.admin.user.AddUser.doExecute(AddUser.java:144) ... 1 filtered at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:63) ... 7 filtered at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ... 48 filtered at com.atlassian.greenhopper.jira.filters.ClassicBoardRouter.doFilter(ClassicBoardRouter.java:62) ... 7 filtered at com.atlassian.jira.plugin.mobile.web.filter.MobileAppRequestFilter.doFilter(MobileAppRequestFilter.java:37) ... 4 filtered at com.atlassian.jira.plugin.mobile.login.MobileLoginSuccessFilter.doFilter(MobileLoginSuccessFilter.java:54) ... 3 filtered at com.atlassian.diagnostics.internal.platform.monitor.http.HttpRequestMonitoringFilter.doFilter(HttpRequestMonitoringFilter.java:55) ... 8 filtered at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21) ... 66 filtered at com.atlassian.jira.security.JiraSecurityFilter.lambda$doFilter$0(JiraSecurityFilter.java:66) ... 1 filtered at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:64) ... 39 filtered at com.atlassian.jira.servermetrics.CorrelationIdPopulatorFilter.doFilter(CorrelationIdPopulatorFilter.java:30) ... 10 filtered at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21) ... 4 filtered at com.atlassian.web.servlet.plugin.LocationCleanerFilter.doFilter(LocationCleanerFilter.java:36) ... 29 filtered at com.atlassian.jira.servermetrics.MetricsCollectorFilter.doFilter(MetricsCollectorFilter.java:25) ... 25 filtered at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassCastException: co.elastic.apm.agent.impl.async.SpanInScopeRunnableWrapper cannot be cast to java.util.concurrent.Future at com.atlassian.jira.application.DefaultApplicationRoleManager.refreshActiveUsersCount(DefaultApplicationRoleManager.java:243) at com.atlassian.jira.application.DefaultApplicationRoleManager.clearUserCounts(DefaultApplicationRoleManager.java:863) at com.atlassian.jira.application.DefaultApplicationRoleManager.clearUserCountsIfNotInSync(DefaultApplicationRoleManager.java:856) at com.atlassian.jira.application.DefaultApplicationRoleManager.onGroupMembershipsCreated(DefaultApplicationRoleManager.java:712) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ... 1 filtered at java.lang.reflect.Method.invoke(Method.java:498) at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:42) ... 280 more ```
eyalkoren commented 4 years ago

Thanks for reporting this issue! This seems to be a side effect of our instrumentation for capturing async executions.

We may need to black-list some specific atlassian Executor implementation so that we do not wrap Runnables/Callables submitted to it. If you haven't already, please set the log_level to DEBUG, reproduce and attach the entire log (e.g. as a gist). Specifically, we are interested at the startup logs where we can see which classes we instrument.

Next, as a workaround, please try to set the disable_instrumentations config to executor. If this works and you get everything you expect - that's it, just use the agent with this config. The effect may be that we do not trace other asynchronous stuff that we normally do, but this is not necessarily something that would affect you.

vladimirshikhov commented 4 years ago

Next, as a workaround, please try to set the disable_instrumentations config to executor. If this works and you get everything you expect - that's it, just use the agent with this config. The effect may be that we do not trace other asynchronous stuff that we normally do, but this is not necessarily something that would affect you.

Thank you! this resolve my issue

eyalkoren commented 4 years ago

@vladimirshikhov we've implemented a different approach for instrumenting async frameworks. You can try out this one: elastic-apm-agent-1.16.1-SNAPSHOT.jar.zip, without the disable_instrumentations config. We'll be happy to get your feedback if you get the chance.