Based on documentation, fsync with lock=true should block the writes. But what's being noticed is its still writing though its blocking the writes. Is this the expected behavior?
I installed MongoDB locally on my machine and running it as a single node replica set. MongoDB version being used is 4.2.11

I perform fsync as shown here under.
And then attempt a write, it gets blocked. I would cancel it.

And then perform fsync unlock.
It is expected that the write wouldn't have worked, but it is persisted any ways. Is there a bug in fsync?



This can be possible in a scenario when you shut down the blocked insert ( e.g. by control+ C or any other mechanism) but somehow the process did not stopped and after you ran unblock fsync the command still went through in the background and was inserted OR when the insert command was blocked and after that you ran unblock fsync which made the block insert to unblock automatically. I tested this on v 4.4.10 ( on a higher version than yours) and it works perfectly fine as per documentation.
First insert one record
Then use fsync
Then try to insert one more record which will get blocked and subsequently killed using Ctrl + C
Then unblock fsync
Verify that the second insert was not successful ( this is what the expected behavior is)
You can also check the db.serverStatus() before and after to see the difference in "insert" commands accepted by the server. This can provide you hint as to whether the command somehow reached. The info looks like this