ashishkumar50 commented on PR #4934:
URL: https://github.com/apache/ozone/pull/4934#issuecomment-1600305742
> @ashishkumar50, multiple reads are fine concurrently, but if we do not
guard reads **and** writes with either a lock or by putting them into a
synchronized method, then write may happen during reads, and that leads to a
ConcurrentModificationException.
>
> Consider the following example which is a scheduling that can happen in an
env if write happens during iteration:
>
> ```java
> List<String> strs = new ArrayList<>();
> strs.add("foo");
>
> Semaphore sem = new Semaphore(1);
> CountDownLatch latch = new CountDownLatch(2);
>
> Runnable r1 = () -> {
> try {
> sem.acquire();
> latch.countDown();
> latch.await();
> strs.add("bar");
> sem.release();
> } catch (Exception e) {
> e.printStackTrace();
> }
> };
>
> Runnable r2 = () -> {
> try {
> for (String s : strs) {
> latch.countDown();
> latch.await();
> sem.acquire();
> System.out.println(s);
> sem.release();
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> };
>
> new Thread(r1).start();
> new Thread(r2).start();
> ```
>
> This code produces a ConcurrentModificationException consistently.
>
> So @Galsza, I think, either we use a lock around the access to the rootCA
certificate list, or we use synchronized, but we need to guard all accesses, as
the addition of a new rootCA certificate will happen on a different thread than
the one that serves requests and iterates over the list.
>
> I know that the chances to win the lottery is higher than to hit this
here, but still, if we started to think about it, then let's get to the bottom
of it, and have a proper solution.
Yes correct, If request traffic is frequent there is a chance that read
might fail because writes are happening on same object. But as you mentioned
traffic is very less so the chance of happening both read/write together is
rare and even if this happens there is a retry from client which will be
success eventually.
So we can decide whether we should fix this with no chance of failure
because of concurrency.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]