Skip to content

Commit 2f50a9c

Browse files
authored
fix: prevent serialization to leak CurrentInstances (#21277)
During serialization and deserialization of VaadinSession and UI, CurrentInstances may be set but not present in the original instances map, causing the added instance to leak outside the scope of the deserialization hook method. This fix ensures all instances set by the hooks are wiped out before restoring the original instances.
1 parent c6ab3a0 commit 2f50a9c

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

flow-server/src/main/java/com/vaadin/flow/component/Component.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ private void writeObject(ObjectOutputStream out) throws IOException {
839839
try {
840840
out.defaultWriteObject();
841841
} finally {
842+
CurrentInstance.clearAll();
842843
CurrentInstance.restoreInstances(instances);
843844
}
844845
} else {
@@ -858,6 +859,7 @@ private void readObject(ObjectInputStream in)
858859
try {
859860
in.defaultReadObject();
860861
} finally {
862+
CurrentInstance.clearAll();
861863
CurrentInstance.restoreInstances(instances);
862864
}
863865
} else {

flow-server/src/main/java/com/vaadin/flow/server/VaadinSession.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ private void readObject(ObjectInputStream stream)
11101110
resourceRegistry = (StreamResourceRegistry) stream.readObject();
11111111
pendingAccessQueue = new ConcurrentLinkedQueue<>();
11121112
} finally {
1113+
CurrentInstance.clearAll();
11131114
CurrentInstance.restoreInstances(old);
11141115
}
11151116
}
@@ -1142,6 +1143,7 @@ private void writeObject(java.io.ObjectOutputStream stream)
11421143
stream.writeObject(new StreamResourceRegistry(this));
11431144
}
11441145
} finally {
1146+
CurrentInstance.clearAll();
11451147
CurrentInstance.restoreInstances(instanceMap);
11461148
}
11471149
}

0 commit comments

Comments
 (0)