So the situation is that on a given page there are many HTTP requests and each of these need to update a single shared cookie. There is no possibility to control how many requests are made per page, but realistically there can be 10+.
We've seen issues where only the last http request successfully updates the cookie and I am told this is due to browser dependencies.
Is this a known issue in general and are there any strategies for mitigating the risk?
Race conditions can be avoided by proper thread synchronization in critical sections. Thread synchronization can be achieved using a synchronized block of Java code. Thread synchronization can also be achieved using other synchronization constructs like locks or atomic variables like java.
an easy way to fix "check and act" race conditions is to synchronized keyword and enforce locking which will make this operation atomic and guarantees that block or method will only be executed by one thread and result of the operation will be visible to all threads once synchronized blocks completed or thread exited ...
A race condition is an undesirable situation that occurs when a device or system attempts to perform two or more operations at the same time, but because of the nature of the device or system, the operations must be done in the proper sequence to be done correctly.
One strategy is to avoid storing mutable information in the cookie itself, and instead have the cookie be an identifier of some sort that identifies a record in a database of some kind somewhere. Then, your server updates information in the (server-side) database, instead of changing the cookie value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With