error page servlet register twice

41 views
Skip to first unread message

Nhut Thai Le

unread,
Sep 3, 2019, 10:45:57 AM9/3/19
to OPS4J
Hello,

We are using pax-web-extender-whiteboard 7.2.4 on equinox and I have a few error page servlet annotated as followed:
@Component(
service = Servlet.class,
property = {
HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME + "=Error403Servlet",
"alias=/error403",
"osgi.http.whiteboard.servlet.errorPage=403",
"osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=WebviewerServletContextHelper)"
},
scope = ServiceScope.PROTOTYPE
)
public final class Error403Servlet extends HttpServlet {...}

However, sometimes when we start the server, we got this error:
java.lang.IllegalArgumentException: Error page for [403] already registered.
	at org.ops4j.pax.web.service.spi.model.ServiceModel.addErrorPageModel(ServiceModel.java:315)
	at org.ops4j.pax.web.service.internal.HttpServiceStarted.registerErrorPage(HttpServiceStarted.java:961)
	at org.ops4j.pax.web.service.internal.HttpServiceProxy.registerErrorPage(HttpServiceProxy.java:343)
	at org.ops4j.pax.web.extender.whiteboard.internal.element.ServletWebElement.register(ServletWebElement.java:107)
	at org.ops4j.pax.web.extender.whiteboard.internal.WebApplication.registerWebElement(WebApplication.java:392)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
	at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.util.stream.ReferencePipeline.forEach(Unknown Source)
	at org.ops4j.pax.web.extender.whiteboard.internal.WebApplication.addWebElement(WebApplication.java:170)
	at org.ops4j.pax.web.extender.whiteboard.internal.tracker.AbstractTracker.addingService(AbstractTracker.java:193)
	at org.ops4j.pax.web.extender.whiteboard.internal.tracker.AbstractTracker.addingService(AbstractTracker.java:46)
	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
	at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
	at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
	at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:887)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:874)
	at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:132)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:941)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:741)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:675)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:430)
	at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:657)
	at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:341)
	at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:390)
	at org.apache.felix.scr.impl.Activator.access$200(Activator.java:54)
	at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:265)
	at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:254)
	at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:227)
	at org.apache.felix.utils.extender.AbstractExtender.addingBundle(AbstractExtender.java:187)
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:469)
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:1)
	at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
	at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120)
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112)
	at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:168)
	at org.eclipse.osgi.container.Module.publishEvent(Module.java:476)
	at org.eclipse.osgi.container.Module.doStart(Module.java:578)
	at org.eclipse.osgi.container.Module.start(Module.java:449)
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1628)
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1608)
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1579)
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1522)
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

Since the error page is working fine despite this exception, is it a race condition in the service registry that cause this exception? Should this be reported as bug on pax-web or felix scr? We tried to upgrade to pax-web 7.2.10 but still got the same error from time to time

Thai Le


Grzegorz Grzybek

unread,
Sep 10, 2019, 1:58:40 AM9/10/19
to op...@googlegroups.com
Hello Thai

Finally I have some time to tackle all your recent emails related to pax-web. Expect some answers soon.

regards
Grzegorz Grzybek


--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/a5f3e942-754b-4c95-b958-a6cf6c5f75c0%40googlegroups.com.

Grzegorz Grzybek

unread,
Sep 10, 2019, 3:29:50 AM9/10/19
to op...@googlegroups.com
Hello

We have:
 – org.ops4j.pax.web.itest.undertow.WhiteboardR6IntegrationTest#testErrorServlet
 – org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest#testErrorServlet
 – org.ops4j.pax.web.itest.tomcat.WhiteboardR6IntegrationTest#testErrorServlet

which tests servlet with "osgi.http.whiteboard.servlet.errorPage = [ "404", "442", "5xx", "java.io.IOException" ]". This test never failed with such exception...

Questions:
 – did you try debugging and checking what's passed in org.ops4j.pax.web.service.spi.model.ServiceModel#addErrorPageModel? (e.g., value of org.ops4j.pax.web.service.spi.model.ContextModel#classLoader) inside ErrorModel?
 – why do you use scope = prototype?

regards
Grzegorz Grzybek

wt., 3 wrz 2019 o 16:46 Nhut Thai Le <nt...@castortech.com> napisał(a):

Nhut Thai Le

unread,
Sep 10, 2019, 10:54:14 AM9/10/19
to op...@googlegroups.com
Hello,

I'll put the breakpoint at addErrorPageModel and check the value when this error happen again.
About the prototype, i use it because both R6 and R7 recommends in section 140.5

Thai



--
Castor Technologies Inc
460 rue St-Catherine St Ouest, Suite 613 
Montréal, Québec H3B-1A7

CONFIDENTIALITY NOTICE: The information contained in this e-mail is confidential and may be proprietary information intended only for the use of the individual or entity to whom it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any viewing, dissemination, distribution, disclosure, copy or use of the information contained in this e-mail message is strictly prohibited. If you have received and/or are viewing this e-mail in error, please immediately notify the sender by reply e-mail, and delete it from your system without reading, forwarding, copying or saving in any manner. Thank you.
AVIS DE CONFIDENTIALITE: L’information contenue dans ce message est confidentiel, peut être protégé par le secret professionnel et est réservé à l'usage exclusif du destinataire. Toute autre personne est par les présentes avisée qu'il lui est strictement interdit de diffuser, distribuer ou reproduire ce message. Si vous avez reçu cette communication par erreur, veuillez la détruire immédiatement et en aviser l'expéditeur. Merci.

Nhut Thai Le

unread,
Sep 10, 2019, 12:47:57 PM9/10/19
to op...@googlegroups.com
Hi Grzegorz,

Here are some screenshot showing the same 403 error page registered twice, both times they are using the same classLoader:
This is the 1st time the 403 got registered, there was nothing in the erroPageModels map, class loader of the ErrorPageModel is bundle 29
1st403.PNG
This is the 2nd time the 403 error page got registered, as you can see, there is already one 403 error page in the errorPageModels map with different id
whenErrorWithOldModelId.PNG
and it is using the same classloader 
whenErrorWithModelId.PNG
What should be my next step to debug this?

Thai

Jean-Baptiste Onofré

unread,
Sep 10, 2019, 12:53:44 PM9/10/19
to OPS4J
Hi

Is it not the same issue I fixed for the servlet context ? (Service registered twice)

Did you try on Karaf 4.2.6 ?

Regards
JB

Nhut Thai Le

unread,
Sep 10, 2019, 12:58:42 PM9/10/19
to op...@googlegroups.com
Hi JB,
I'm running this on equinox from eclipse osgi launch, haven't try it on karaf yet. Do you have a reference to the bug you fixed ?

Thai

Jean-Baptiste Onofré

unread,
Sep 10, 2019, 1:07:07 PM9/10/19
to OPS4J
Let me find jira and commit id.

Regards
JB

Grzegorz Grzybek

unread,
Sep 12, 2019, 1:38:58 AM9/12/19
to op...@googlegroups.com
Thai, good investigation

So when we're already in the debugger, please:
 - put a breakpoint in ErrorPageModel constructor
 - when its hit, show me the stacktrace

So - each time ErrorPageModel is constructed, collect the thread trace that constructs this model - we can try finding the reasons of duplicate creation. Discovering that it's "added" to models is only a consequence. Now we should find the reason ;).

regards
Grzegorz Grzybek

Nhut Thai Le

unread,
Sep 12, 2019, 10:00:12 AM9/12/19
to op...@googlegroups.com
Hi Grzegorz,

Thank you for looking into this, here is the call stack from the 1st call to ErrorPageModel constructor for 403:
1st403.PNGand below is the 2nd time, since the call stack for the 2nd hit is quite long, i took 2 screenshots:
2nd403_1.PNG

2nd403_2.PNGPlease let me know if you need more info

Thai

Grzegorz Grzybek

unread,
Sep 12, 2019, 10:13:16 AM9/12/19
to op...@googlegroups.com
I'll analyze the screenshots tomorrow. But please - is there a chance to "copy stack trace" from eclipse debugger? (it can be done in IDEA)...

regards
Grzegorz Grzybek

Nhut Thai Le

unread,
Sep 12, 2019, 12:09:36 PM9/12/19
to op...@googlegroups.com
Hi Grzegorz,

I didnt know i can copy stacktrace as txt. I tried again to get the call stack but i dont get the 2nd registration of 403 anymore, I have tried 5 times. As this is not always reproducible, i'll keep an eye on it and post back the txt version of the call stack when i got the error again. In the meantime, the call stack of the 2nd registration of 403 is in the screenshot i sent earlier.

Thai


Grzegorz Grzybek

unread,
Sep 13, 2019, 8:07:28 AM9/13/19
to op...@googlegroups.com, Jean-Baptiste Onofré
Hello

I analyzed the screenshots of stack traces and there are two paths where the same error page model is registered:
 - normal path, where SCR @Component activation registers Servlet.class service that leads to registration of ErrorPageModel - tha's fine
 - 2nd path, where org.ops4j.pax.web.extender.whiteboard.internal.WebApplication#setServletContextHelper() is called upon detection of org.osgi.service.http.context.ServletContextHelper OSGi service

In 2nd path, org.ops4j.pax.web.extender.whiteboard.internal.WebApplication#setServletContextHelper() is called, but it first should call org.ops4j.pax.web.extender.whiteboard.internal.WebApplication#unregisterHttpContext() to unregister existing elements.

The problem I sense is that org.ops4j.pax.web.extender.whiteboard.internal.WebApplication#hasHttpContextMapping() probably returns "false" somehow, so there's no registration.

+Jean-Baptiste Onofré do you remember something related to duplicate registration? PAXWEB-1197 was about session listeners only...

Thai - can you create PAXWEB issue, so we can track the problem there?

regards
Grzegorz Grzybek


Nhut Thai Le

unread,
Sep 13, 2019, 12:20:14 PM9/13/19
to op...@googlegroups.com, Jean-Baptiste Onofré
Hi guys,
I open the bug for this issue:

Thank you again for looking at this.

Thai

Reply all
Reply to author
Forward
0 new messages