aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-26 18:15:51 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-26 18:15:51 +1200
commit28f49cce7fd77194a406bb87b20155b7872ccb62 (patch)
tree95ddaf2af201b67e28588aaacc698728ba3b1cea /src
parent6148a3c2d873f5490cc4a55bc7e326c7d293405b (diff)
downloadtraccar-server-28f49cce7fd77194a406bb87b20155b7872ccb62.tar.gz
traccar-server-28f49cce7fd77194a406bb87b20155b7872ccb62.tar.bz2
traccar-server-28f49cce7fd77194a406bb87b20155b7872ccb62.zip
Fix async session deadlock (fix #1428)
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/web/AsyncServlet.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/org/traccar/web/AsyncServlet.java b/src/org/traccar/web/AsyncServlet.java
index 20a71ec1c..a62b98c59 100644
--- a/src/org/traccar/web/AsyncServlet.java
+++ b/src/org/traccar/web/AsyncServlet.java
@@ -110,12 +110,12 @@ public class AsyncServlet extends BaseServlet {
public void run(Timeout tmt) throws Exception {
synchronized (AsyncSession.this) {
logEvent("sessionTimeout");
- Context.getConnectionManager().removeListener(devices, dataListener);
- synchronized (asyncSessions) {
- asyncSessions.remove(userId);
- }
destroyed = true;
}
+ Context.getConnectionManager().removeListener(devices, dataListener);
+ synchronized (asyncSessions) {
+ asyncSessions.remove(userId);
+ }
}
};
@@ -180,14 +180,18 @@ public class AsyncServlet extends BaseServlet {
private static final Map<Long, AsyncSession> asyncSessions = new HashMap<>();
public static void sessionRefreshUser(long userId) {
- asyncSessions.remove(userId);
+ synchronized (asyncSessions) {
+ asyncSessions.remove(userId);
+ }
}
public static void sessionRefreshDevice(long deviceId) {
- Iterator<Entry<Long, AsyncSession>> iterator = asyncSessions.entrySet().iterator();
- while (iterator.hasNext()) {
- if (iterator.next().getValue().hasDevice(deviceId)) {
- iterator.remove();
+ synchronized (asyncSessions) {
+ Iterator<Entry<Long, AsyncSession>> iterator = asyncSessions.entrySet().iterator();
+ while (iterator.hasNext()) {
+ if (iterator.next().getValue().hasDevice(deviceId)) {
+ iterator.remove();
+ }
}
}
}