adriannistor opened a new pull request #1248: URL: https://github.com/apache/hive/pull/1248
Field `writers` is a `HashMap` ([line 70](https://github.com/apache/hive/blob/c93d7797329103d6c509bada68b6da7f907b3dee/ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java#L70)), i.e., not thread-safe. Accesses to field `writers` are protected by synchronization on `lock`, e.g., at lines: [141-144](https://github.com/apache/hive/blob/c93d7797329103d6c509bada68b6da7f907b3dee/ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java#L141-L144), [212-213](https://github.com/apache/hive/blob/c93d7797329103d6c509bada68b6da7f907b3dee/ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java#L212-L213), and [212-215](https://github.com/apache/hive/blob/c93d7797329103d6c509bada68b6da7f907b3dee/ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java#L212-L215). However, the `writers.remove()` at [line 249](https://github.com/apache/hive/blob/c93d7797329103d6c509bada68b6da7f907b3dee/ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java#L249) is protected by synchronization on `INSTANCE`, **not** on `lock`. Synchronizing on 2 different objects does not ensure mutual exclusion. This is because 2 threads synchronizing on different objects can still execute in parallel at the same time. Note that lines [215](https://github.com/apache/hive/blob/c93d7797329103d6c509bada68b6da7f907b3dee/ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java#L215) and [249](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/llap/LlapOutputFormatService.java#L249) are modifying `writers` with `put()` and `remove()`, respectively. # The Code for This Fix This fix is very simple: just change `synchronized (INSTANCE)` to `synchronized (lock)`, just like the methods containing the other lines listed above. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org