When using console-based logging alongside file-based logging at a low level (such as DEBUG) in a Couchbase Lite Java application on Windows, the replication eventually gets stuck due to waiting for a logging call that never returns.
1. Create a simple Java app (source code attached as Main.java ) designed to synchronize a non-trivial number of documents (my tests reproduce after approximately 50000 documents) from a remote Sync Gateway, ideally with a good network to ensure network isn't the bottleneck.
Ideally add some way to keep track of replication progress (via the replicator status).
2. Enable console logging at debug-level and file-based logging:
3. Run the app on Windows.
The app synchronizes all of the documents as expected.
The app eventually stops logging from Couchbase Lite and the replication makes no further progress.
I grabbed the thread dump via Jstack when the app got into this 'stuck' state (thread_dump.txt) and can see the following:
As you can see in this, the reason that replication is making no further progress is because the thread responsible from consuming new messages from the websocket is stuck in Lite Core's logging method.
I tried to get more detail about what Lite Core is doing at this stage but I guess it wasn't compiled with debug symbols as the stacktrace in windbg.exe was just addresses.
Trying to understand the problem a bit better, I made a few adjustments and found that this does not occur in the following situations:
- When you use VERBOSE level instead of DEBUG-level, implying an issue specifically with DEBUG level or just the volume of logging generated.
- When you use only console-based or only file-based logging, implying there is a potential deadlock caused by having 2 outputs.
- When the application is running on Linux, implying this is Windows-specific.
Do not enable debug logging for console logging.