diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-07-29 15:51:33 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2013-07-29 15:51:33 +0300 |
commit | 3a373efe27780f3ffd1f0e01fb6dabdb65af590c (patch) | |
tree | f7307d3b5c3cb53c35e99e9cd370fb14aa1438e8 /server/src/com | |
parent | 421922705b6e5bd2abf6a11d83f5b4a4791f968a (diff) | |
download | vaadin-framework-3a373efe27780f3ffd1f0e01fb6dabdb65af590c.tar.gz vaadin-framework-3a373efe27780f3ffd1f0e01fb6dabdb65af590c.zip |
Fix race condition that might leave access queue unpurged (#12277)
Merge: no
Change-Id: Iee1012486906d8c2c46cef94cfcd6d2b399d7a6b
Diffstat (limited to 'server/src/com')
-rw-r--r-- | server/src/com/vaadin/server/VaadinService.java | 19 | ||||
-rw-r--r-- | server/src/com/vaadin/server/VaadinSession.java | 12 |
2 files changed, 29 insertions, 2 deletions
diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index f603fbd1e9..17bce7ad15 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -1655,6 +1655,23 @@ public abstract class VaadinService implements Serializable { FutureAccess future = new FutureAccess(session, runnable); session.getPendingAccessQueue().add(future); + ensureAccessQueuePurged(session); + + return future; + } + + /** + * Makes sure the pending access queue is purged for the provided session. + * If the session is currently locked by the current thread or some other + * thread, the queue will be purged when the session is unlocked. If the + * lock is not held by any thread, it is acquired and the queue is purged + * right away. + * + * @since 7.1.2 + * @param session + * the session for which the access queue should be purged + */ + public void ensureAccessQueuePurged(VaadinSession session) { /* * If no thread is currently holding the lock, pending changes for UIs * with automatic push would not be processed and pushed until the next @@ -1677,8 +1694,6 @@ public abstract class VaadinService implements Serializable { } catch (InterruptedException e) { // Just ignore } - - return future; } /** diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index 8f27241384..8de01e22bc 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -926,6 +926,18 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { } finally { getLockInstance().unlock(); } + + /* + * If the session is locked when a new access task is added, it is + * assumed that the queue will be purged when the lock is released. This + * might however not happen if a task is enqueued between the moment + * when unlock() purges the queue and the moment when the lock is + * actually released. This means that the queue should be purged again + * if it is not empty after unlocking. + */ + if (!getPendingAccessQueue().isEmpty()) { + getService().ensureAccessQueuePurged(this); + } } /** |