Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed deadlock in SMPPSession/AbstractSession close methods #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TomasAndersen
Copy link

I am using the jsmpp API to listen for incoming SMS messages on a socket connection.
In average this socket connection stopped every 24 hours. I could also make it stop by breaking the network connection between my server and the SMPP Gateway.

I turned out that it was a deadlock caused by the EnquireLinkSender thread waiting for the PDUReader thread and visa versa.

This pull request moves all cleanup code into the superclass (AbstractSession) and I have added a check for which thread is calling the close method.

After running with this patch the SMPP API is able to close properly without any deadlock.

I have added a watchdog in my code outside the SMPP API that reconnects the SMPP Session when this happens instead of making the jsmpp API handle this and restart itself.

…in the cleanup of SMPPSession and AbstractSession.

The EnquireLink and PDUReader threads both waited for each other to end.
Moved all close handling to the parent object (AbstractSession)
@dpocock
Copy link

dpocock commented Jan 6, 2015

Hi Tomas, thanks for this contribution. I've merged your work here: opentelecoms-org/jsmpp@5da83c0

@04mahajan-98
Copy link

04mahajan-98 commented Apr 28, 2022

Hi @TomasAndersen.I am facing problem while calling session.close().I am using jsmpp 2.0.1 version That's why I have to override the close method and written the stopEnquireLinkSender() method to stop the enquire link sender thread.Below is the code to stop the thread:-
//////////////////////////////////////////////////

Field enquireLinkSenderField;
try {
enquireLinkSenderField = this.getClass().getSuperclass()
.getDeclaredField("enquireLinkSender");
enquireLinkSenderField.setAccessible(true);
Class noparams[] = {};
Object enquireLinkSenderThread = enquireLinkSenderField.get(this);
if (enquireLinkSenderThread != null && Thread.currentThread() != enquireLinkSenderThread ) {
LOGGER.info("Trying to stop enquirelink Sender thread.");
Method m = enquireLinkSenderThread.getClass().getMethod(
"isAlive", noparams);

			while ((Boolean) m.invoke(enquireLinkSenderThread, noparams)) {
				Method joinMethod = enquireLinkSenderThread.getClass()
						.getMethod("join", noparams);
				joinMethod.invoke(enquireLinkSenderThread, noparams);
									
				LOGGER.info(
						"Session {} is closed and enquireLinkSender stopped",
						this.getSessionId());
			}

		}

	}

But session got hanged sometimes when called session.close().And the I have to restart the server to connect to smpp again and again.What changes need to be done here so that It won't behave abnormal

@TomasAndersen
Copy link
Author

Hi @04mahajan-98! As this is 8 years ago I am afraid I haven't any immediate answer to give you as I have forgotten a lot of this. At least not without spending time debugging and testing. Is there a reason for why you are sticking to the old version? I guess I would focus on upgrading the library to the latest version of the https://github.com/opentelecoms-org/jsmpp library instead and try it out. I hope there are not too many breaking changes to the API so the work of upgrading is too hard. I detected the error when debugging a project I stopped working on 6 years ago and opened a PR so I don't work on this project on a regular basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants