Details
Description
Through studying the semaphore logic of the Thread Blocking environment a race condition was discovered causing another thread leak. Due to time-slicing it could happen that the Servlet Container supplied thread decides to use the semaphore logic to block and another thread trying to send a response decides the semaphore logic is not in effect yet and will not release the semaphore eventually. This causes the Servlet Container supplied thread to block and never gets unblocked.
public void respondWith(final ResponseHandler handler) throws Exception {
try {
super.respondWith(handler);
} finally {
if (semaphore == null) {
--> timeslicing
blockResponse = false;
} else {
semaphore.release();
}
}
}
public void blockUntilRespond() throws InterruptedException {
if (blockResponse) {
--> timeslicing
semaphore = new Semaphore(1);
semaphore.acquire();
boolean acquired = semaphore.tryAcquire(TIMEOUT, TimeUnit.MINUTES);
if (acquired) {
semaphore.release();
} else {
// log some warning
semaphore.release();
}
}
}
The thread blocking code (ThreadBlockingAdaptingServlet) should use immutable objects to avoid any synchronization issues.
public void respondWith(final ResponseHandler handler) throws Exception {
try {
super.respondWith(handler);
} finally {
if (semaphore == null) {
--> timeslicing
blockResponse = false;
} else {
semaphore.release();
}
}
}
public void blockUntilRespond() throws InterruptedException {
if (blockResponse) {
--> timeslicing
semaphore = new Semaphore(1);
semaphore.acquire();
boolean acquired = semaphore.tryAcquire(TIMEOUT, TimeUnit.MINUTES);
if (acquired) {
semaphore.release();
} else {
// log some warning
semaphore.release();
}
}
}
The thread blocking code (ThreadBlockingAdaptingServlet) should use immutable objects to avoid any synchronization issues.
Activity
- All
- Comments
- History
- Activity
- Remote Attachments
- Subversion
Simplify interaction with semaphore. Make ThreadBlockingRequestResponse immutable.