-
-
Notifications
You must be signed in to change notification settings - Fork 756
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
Memory leak on Tomcat when websocket endpoint terminated #332
Comments
Nevermind on this issue. I have a call to: |
Ok I need more information about that. Can you paste the Thread dump here? Also, are you destroying Broadcaster (because every new Broadcaster will create a new BroadcasterConfig => 2 executors) Did you know that you can share the Executor between Broadcaster?
|
This does bring up a separate question for me. Is there a way for multiple clients to share the same broadcaster, while receiving different dispatches? My current code for adding a subscription: public boolean subscribe(String userName, String realm, FeedToken.FeedType feedType, Object resource)
throws InvalidTargetObjectTypeException{
if(!(resource instanceof AtmosphereResource)){
throw new InvalidTargetObjectTypeException("JSON Feed Dispatcher expects subscription resource" +
" of type AtmosphereResource");
}
boolean subscribed = this.isSubscribed(userName, realm, feedType);
//make sure they are not already subscribed before creating a new broadcaster.
if(!subscribed){
AtmosphereResource atmoResource = (AtmosphereResource)resource;
atmoResource.setBroadcaster(broadcasterFactory.get());//recreate a new broadcaster for this resource
broadcasterFactory.add(atmoResource.getBroadcaster(),
new SubscriptionKey(userName, realm, feedType));
AtmosphereUtils.suspend(atmoResource);
}
return subscribed;
} And then for dispatching Feeds: public Future<String> dispatch(FeedToken feed, DispatchType dispatchType){
Future<String> future = null;
final ObjectMapper mapper = new ObjectMapper();
try{
SubscriptionKey subscriptionKey = new SubscriptionKey(feed.getUserId(), feed.getRealmId(), feed.getType());
Broadcaster broadcaster = this.getBroadcaster(subscriptionKey);
if(broadcaster !=null){
final Map<String, Object> objectMap = new HashMap<String, Object>();
objectMap.put("dispatchType", dispatchType);
objectMap.put("feeds", feed);
future = broadcaster.broadcast(mapper.writeValueAsString(objectMap));
}
}
catch (IOException ioErr){
logger.log(Level.SEVERE, "Unable to serialize " + feed.getClass().getName() + " as String");
logger.log(Level.SEVERE, feed.toString());
}
return future;
} |
Yes, you can share the same Broadcaster and filter broadcast using BroadcastFilter or PerRequestBroadcastFilter. Also have you configured a BroadcasterFactoryLifecyclePolicy I don't think there is a leak here but if you can share a thread dump I will be sure |
There is not. After updating with the above code, there is no leak. Thanks, I would look into the Filters.
|
Ok, I was able to write a filter that handles multiple subscriptions on the same broadcaster. Now I have 2 waiting threads instead of 2 or more per client. Thanks for the advice. |
Great news! I've also added official documentation |
Very useful. Thanks! |
Threads continue to be created on Tomcat every time the endpoint connection is lost "due to a protocol error". The Async-Write and BroadcasterConfig threads keep duplicated when the Atmosphere resource is re-sent to the server. I am using Spring MVC controller to subscribe a client to the BroadcastFactory. Each re-connect subscribe is called, but the client is already subscribed, so you wouldn't expect these threads to keep duplicating.
The text was updated successfully, but these errors were encountered: