You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Lescisin, Michael" <Mi...@uhn.ca> on 2021/04/27 14:51:55 UTC

Stopping Apache Sling Launchpad upon exception in OSGi bundle

Hi there,

I was wondering if somebody could kindly help me with the following issue. We are developing a clinical archive based on Apache Sling (https://github.com/ccmbioinfo/lfs) and are using the Sling Launchpad to load all artifacts. One such artifact is org.apache.felix.http.jetty (specified in https://github.com/ccmbioinfo/lfs/blob/dev/distribution/src/main/provisioning/99-standalone.txt) which (by default) binds to and listens on TCP port 8080. When another process is listening on this port and thus causes org.apache.felix.http.jetty to be unable to bind to this port, as expected, I see java.net.BindException: Address already in use in sling/logs/error.log. However, despite this error, the rest of the artifacts are loaded, and the executable JAR does not terminate.

Could someone kindly explain how Sling Launchpad can be reconfigured so that the executable JAR will terminate if org.apache.felix.http.jetty throws a java.net.BindException?

Thank you,

Michael

This e-mail may contain confidential and/or privileged information for the sole use of the intended recipient.
Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited.
If you have received this e-mail in error, please contact the sender and delete all copies.
Opinions, conclusions or other information contained in this e-mail may not be that of the organization.

If you feel you have received an email from UHN of a commercial nature and would like to be removed from the sender's mailing list please do one of the following:
(1) Follow any unsubscribe process the sender has included in their email
(2) Where no unsubscribe process has been included, reply to the sender and type "unsubscribe" in the subject line. If you require additional information please go to our UHN Newsletters and Mailing Lists page.
Please note that we are unable to automatically unsubscribe individuals from all UHN mailing lists.


Patient Consent for Email:

UHN patients may provide their consent to communicate with UHN about their care using email. All electronic communication carries some risk. Please visit our website here<https://www.uhn.ca/PatientsFamilies/Patient_Safety_Advocacy/Privacy/Documents/Email_consent_and_safety.pdf> to learn about the risks of electronic communication and how to protect your privacy. You may withdraw your consent to receive emails from UHN at any time. Please contact your care provider, if you do not wish to receive emails from UHN.

Re: Stopping Apache Sling Launchpad upon exception in OSGi bundle

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Apr 27, 2021 at 6:45 PM Eric Norman <en...@apache.org> wrote:
> ...I don't believe there is currently any configuration for the Apache Felix
> Jetty Based Http Service that would do that automatically...

I also think there's no built-in way to achieve what you want.

In addition to Eric's suggestions, you might implement an Appender
service [1] and use the log message to trigger a shutdown when you
detect the expected failure message.

I've never used that feature myself but the docs say it works ;-)

-Bertrand

[1] https://sling.apache.org/documentation/development/logging.html#appenders-as-osgi-services-1

Re: Stopping Apache Sling Launchpad upon exception in OSGi bundle

Posted by Eric Norman <en...@apache.org>.
Hi Michael,

I don't believe there is currently any configuration for the Apache Felix
Jetty Based Http Service that would do that automatically.

It seems to me that there are a couple of options that you may consider:

   1. A "fail before startup" solution where you could utilize some other
   tooling in your startup script to check if the TCP port is already being
   used before attempting to launch the sling launchpad.
   2. A "fail during startup" solution where you could modify the jetty
   http bundle code (and optional configuration?) to catch the specific
   BindException and initiate an orderly shutdown when that happens.  The
   felix project should consider any patches you submit for consideration to
   be included in the next release.
   3. A "fail after monitor" solution where your distribution could provide
   your own custom OSGi component that waits for a duration for all required
   services to become available.  If the monitored required services do not
   become available then initiate an orderly shutdown.  Perhaps some
   integration with the felix "healthcheck" apis could be useful here?

Regards,
Eric

On Tue, Apr 27, 2021 at 8:03 AM Lescisin, Michael <Mi...@uhn.ca>
wrote:

> Hi there,
>
> I was wondering if somebody could kindly help me with the following issue.
> We are developing a clinical archive based on Apache Sling (
> https://github.com/ccmbioinfo/lfs) and are using the Sling Launchpad to
> load all artifacts. One such artifact is org.apache.felix.http.jetty
> (specified in
> https://github.com/ccmbioinfo/lfs/blob/dev/distribution/src/main/provisioning/99-standalone.txt)
> which (by default) binds to and listens on TCP port 8080. When another
> process is listening on this port and thus causes
> org.apache.felix.http.jetty to be unable to bind to this port, as expected,
> I see java.net.BindException: Address already in use in
> sling/logs/error.log. However, despite this error, the rest of the
> artifacts are loaded, and the executable JAR does not terminate.
>
> Could someone kindly explain how Sling Launchpad can be reconfigured so
> that the executable JAR will terminate if org.apache.felix.http.jetty
> throws a java.net.BindException?
>
> Thank you,
>
> Michael
>
> This e-mail may contain confidential and/or privileged information for the
> sole use of the intended recipient.
> Any review or distribution by anyone other than the person for whom it was
> originally intended is strictly prohibited.
> If you have received this e-mail in error, please contact the sender and
> delete all copies.
> Opinions, conclusions or other information contained in this e-mail may
> not be that of the organization.
>
> If you feel you have received an email from UHN of a commercial nature and
> would like to be removed from the sender's mailing list please do one of
> the following:
> (1) Follow any unsubscribe process the sender has included in their email
> (2) Where no unsubscribe process has been included, reply to the sender
> and type "unsubscribe" in the subject line. If you require additional
> information please go to our UHN Newsletters and Mailing Lists page.
> Please note that we are unable to automatically unsubscribe individuals
> from all UHN mailing lists.
>
>
> Patient Consent for Email:
>
> UHN patients may provide their consent to communicate with UHN about their
> care using email. All electronic communication carries some risk. Please
> visit our website here<
> https://www.uhn.ca/PatientsFamilies/Patient_Safety_Advocacy/Privacy/Documents/Email_consent_and_safety.pdf>
> to learn about the risks of electronic communication and how to protect
> your privacy. You may withdraw your consent to receive emails from UHN at
> any time. Please contact your care provider, if you do not wish to receive
> emails from UHN.
>

Re: Stopping Apache Sling Launchpad upon exception in OSGi bundle

Posted by Robert Munteanu <ro...@apache.org>.
On Wed, 2021-04-28 at 22:39 +0200, Robert Munteanu wrote:
> Hi Michael,
> 
> On Tue, 2021-04-27 at 14:51 +0000, Lescisin, Michael wrote:
> > Could someone kindly explain how Sling Launchpad can be
> > reconfigured so
> > that the executable JAR will terminate if
> > org.apache.felix.http.jetty
> > throws a java.net.BindException?
> 
> By looking at the code, it seems that the bundle's activator errors
> out. If that is the case, the org.apache.felix.http.jetty bundle
> should
> not start, and remain in a RESOLVED state.

Sorry, I spoke to soon. Exceptions are caught and logged, so they don't
prevent the bundle from starting.

Thanks,
Robert


Re: Stopping Apache Sling Launchpad upon exception in OSGi bundle

Posted by Robert Munteanu <ro...@apache.org>.
Hi Michael,

On Tue, 2021-04-27 at 14:51 +0000, Lescisin, Michael wrote:
> Could someone kindly explain how Sling Launchpad can be reconfigured so
> that the executable JAR will terminate if org.apache.felix.http.jetty
> throws a java.net.BindException?

By looking at the code, it seems that the bundle's activator errors
out. If that is the case, the org.apache.felix.http.jetty bundle should
not start, and remain in a RESOLVED state.

To validate that, you could write a small bundle with a BundleListener
[1] that checks when the bundle goes through the STARTING -> STOPPING -
> RESOLVED state.

I think this is not fool-proof, because you can't be certain why the
bundle is stopping. A better way would be for the felix http jetty
bundle to expose a way of notifying other bundles when binding fails. 

Thanks,
Robert

[1]:
https://docs.osgi.org/javadoc/osgi.core/7.0.0/org/osgi/framework/BundleListener.html