INT-4237: FWMH: Acquire Lock Before Flushing

JIRA: https://jira.spring.io/browse/INT-4237

It was possible to flush (close) the file while a write was in process; more likely when
`flushWhenIdle` is false.

This probably would not occur in the real world, just tests with short flush intervals,
but certainly possible.

There is already a lock used to prevent concurrent writes while appending; use the same
lock when flushing.
This commit is contained in:
Gary Russell
2017-03-01 09:26:38 -05:00
committed by Artem Bilan
parent da7ff2502c
commit e19a376aef
3 changed files with 97 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,13 +34,16 @@ import org.springframework.messaging.MessagingException;
*
*/
public abstract class WhileLockedProcessor {
private final Object key;
private final LockRegistry lockRegistry;
public WhileLockedProcessor(LockRegistry lockRegistry, Object key) {
this.key = key;
this.lockRegistry = lockRegistry;
}
public final void doWhileLocked() throws IOException {
Lock lock = this.lockRegistry.obtain(this.key);
try {
@@ -65,4 +68,5 @@ public abstract class WhileLockedProcessor {
* @throws IOException Any IOException.
*/
protected abstract void whileLocked() throws IOException;
}