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

Fix for race condition #10

Merged
merged 1 commit into from
Apr 4, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -428,34 +428,34 @@ private Object translate(Object msg) {

protected void executeAsyncWrite(final AtmosphereResource<?, ?> resource, final Object msg, final BroadcasterFuture future) {

synchronized (resource) {
if (resource.getAtmosphereResourceEvent().isCancelled()) {
return;
}

final AtmosphereResourceEvent event = resource.getAtmosphereResourceEvent();
event.setMessage(msg);

if (resource.getAtmosphereResourceEvent() != null && !resource.getAtmosphereResourceEvent().isCancelled()
&& HttpServletRequest.class.isAssignableFrom(resource.getRequest().getClass())) {
try {
HttpServletRequest.class.cast(resource.getRequest())
.setAttribute(CometSupport.MAX_INACTIVE, System.currentTimeMillis());
}
catch (Exception t) {
// Shield us from any corrupted Request
logger.warn("Preventing corruption of a recycled request: resource" + resource, event);
resources.remove(resource);
if (future != null) {
future.cancel(true);
bc.getAsyncWriteService().execute(new Runnable(){
@Override
public void run() {
synchronized (resource) {
if (resource.getAtmosphereResourceEvent().isCancelled()) {
return;
}

final AtmosphereResourceEvent event = resource.getAtmosphereResourceEvent();
event.setMessage(msg);

if (resource.getAtmosphereResourceEvent() != null && !resource.getAtmosphereResourceEvent().isCancelled()
&& HttpServletRequest.class.isAssignableFrom(resource.getRequest().getClass())) {
try {
HttpServletRequest.class.cast(resource.getRequest())
.setAttribute(CometSupport.MAX_INACTIVE, System.currentTimeMillis());
}
catch (Exception t) {
// Shield us from any corrupted Request
logger.warn("Preventing corruption of a recycled request: resource" + resource, event);
resources.remove(resource);
if (future != null) {
future.cancel(true);
}
return;
}
}
return;
}
}

bc.getAsyncWriteService().execute(new Runnable(){
@Override
public void run() {
broadcast(resource, event);
if (resource instanceof AtmosphereEventLifecycle) {
((AtmosphereEventLifecycle) resource).notifyListeners();
Expand All @@ -464,8 +464,8 @@ public void run() {
future.done();
}
}
});
}
}
});
}

protected void checkCachedAndPush(final AtmosphereResource<?, ?> r, final AtmosphereResourceEvent e) {
Expand Down