-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bookmark file is being used by another process #262
Comments
Hi there and welcome to this repository! A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it. |
I think we need to make your issue reproducible. Could you please create a GitHub repo with a small sample showcasing the issue? Please also provide the steps needed to get the exception. |
Hello, this issue is rather problematic i hoped to do the same and ended with the same error. I noticed it even prevent storing any log for the application suffering the problem. |
Hi @julichan! I'll see if I can reproduce the issue after the summer vacations. I hope you can work around the issue until then. |
Thanks @FantasticFiasco, for this fix i wish to provide you further information. I believed the RollingFileSink had the same problem as the HttpSink but here's what i found during the investigation:
On our side, we found a temporary alternative to the http sink, it's the netstandsard rollingfilesink in net48 + filebeat but this involve a lot of extra configuration in filebeat and logstash. We hope to hear from you soon. Perhaps you can handle the bookmark file through the sharedfile object too. |
Hello, @FantasticFiasco,
If you mind, i could provide a merge request myself if i have time before you attempt to make a fix. My proposal is to fix the portabletimer lock at dispose and to create an alternative portabletimer that can be used instead when a crossapp option is enabled in the setting. Or if you don't want a new option, i can just replace the portabletimer lock with an os mutex. |
Thanks for the added information. I'll take a look at this issue when the summer vacations are over here in Sweden. I'll definitely wan't to make sure that we are using the correct internal dependencies to the file sink. |
Hello @FantasticFiasco, |
I'll try to reproduce this in this week or in next. One thing that gets me confused is that it will require two different applications to reproduce the issue, is this correct? I don't think this sink has been built to support two different applications logging to the same buffer files. Although you mention that there is a problem here since the bookmark file is locked, another much greater problem is the fact that both applications will think that they are responsible for sending the log events over the network. That's one reason why you are successful using Filebeat, it's only running as one instance and it has a clear responsibility of sending the log events. Having two separate applications, sharing the same buffers files and bookmark file is like running two instances of Filebeat, one will surely fail or you will end up with duplicate log events on the log server. |
Hello @FantasticFiasco , Haha, i'm quite sure you can also reproduce it with just one application and two instances of the sink sharing the same buffer althrough i haven't tested that. You know i think that serilog shouldn't fail where log4net and nlog succeeds. The http sink shouldn't fail where the others succeeds either. Plus you should know that even for a single application, iis will run multiple instance of it so it should be supported even if only for this case. It doesn't matter if multiple sources sends the log if the bookmark file is handled properly, the logs won't be sent as duplicates. :) I'm trusting you on this one. I know you can do it. 👍 🥇 |
Again, I wouldn't know why you would do that, the sink hasn't been implemented with that use case in mind. Regarding the comparison with log4net and nlog, I'm not in competition with either of them, nor do they dictate the requirements of this sink. Regarding usage in IIS, I'm no expert in IIS, most of my experience comes from working in cloud environments. Are you referring to worker threads in the app pool when you mention instances, or is instances something else? |
I think this could be due to multiple reasons, let me put them down one by one
|
Hello and happy new year, It's pretty easy to reproduce the bug but it seems you still need help here is the case: iis has a recycling process which works by creating a second instance of the web application (you can see two w3wp.exe at that time). Well in our case we notice that behaviour in prod only as it is probably happening too fast in dev but you can see the gist of it: two instances of an app means two instance of the sink with identical settings even for a short time and no way around this.
Now this is way behind me but i also remember reproducing this using multiple instance of the sink in the same app. Anyway the sink was embedded in an async sink in case that helps. We also have reasons to have multiple apps sharing the same sink: multiple iis web apps using same code and configuration with logs that had the same destination. Splitting the buffers is not an option as it would require reworking a large monolyth and large deployment code. We've tried work around but no easy solution would allow to resume sending unsent logs after recycling or app shutdown... Http sink has been then deemed unsuable for us. Now you might still not consider this a use case. It's sad to get such an answer when all other sinks support this. I don't mean to stir a fight but Fiasco refused that i provide a MR and now i have other priorities too... |
@janichirag11, regarding your questions.
Don't know. The test suite is not running in IIS, nor do I have any experience in hosting my applications there. But I would love a GitHub repository with a sample application showcasing the issue, with clear instructions on how to configure and host the application in IIS. With this level of detail I think I would be able to understand the use case a bit more.
Are we talking about the folder hosting the buffer files and the bookmark file? If yes, then the application process will need write permissions to this folder.
Maybe. The locking strategy selected for the buffer files and the bookmark file is not the same. @julichan, regarding your comments.
My comment from 6 months ago ended with me asking you a very specific question on the subject of IIS. I specifically told you that "I'm no expert in IIS...". I didn't get an answer from you, thus my investment in this issue stopped. Let me try to explain. I don't know whether you've published open source. I have a couple of repositories here on GitHub that have gotten to a level where developers are asking me questions, filing issues and proposing feature requests. In these engagements I will try my best to provide answers. But the problem is that there's always more of you than there is of me 😃 We have an uneven relationship here. We're engaging in this issue, and you've made an investment in this specific issue (thanks!). I'm engaging in all interactions across all my repositories, while still maintaining dependencies, and sporadically implement new features. You will have to fight for my priority. The best way you do that is to optimize for the time I will have to invest. If you leave something open ended, if you force me to find my way to a reproducible sample, then your priority is downgraded. I don't think this is unfair, not to you and not to me. Especially when you, as you say, work for a company and get paid for doing this. Me? I don't get paid for providing this as open source. We don't share the same incentive for spending time on this. This is open source, you can fork my code, you can suite it to fit your needs. The license gives you this right!
I am happy for you, you've solved your problem and can continue with focusing on the important parts of your business! I don't mind this at all. There is no benefit for me, direct or indirect, from you using this codebase. You should use it only if you find it valuable. Again, this is open source, you are free to use it and there is no downside for either of us if you don't.
Yes, I definitely need help here 😄 Thanks for the explanation regarding recycling in IIS. But I would like to push back on the proposed solution. This sink has never been implemented to support the use case where multiple different applications are sharing the same buffer files. I don't think this is something that we will opt to support. However, IIS is a major player in the .NET ecosystem and if we have a problem with recycling processes it is something we might have to address. But the solution I would propose is one that would handle the recycling problem, where we handle the fact that two processes in a short time tries to access the same file. This solution seems much easier to tackle, using e.g. retries, than one where multiple processes for a long time share access to the buffer file. @janichirag11, would this be sufficient to you? In the that case it does, I would still need help setting this up in IIS. A sample application and instructions on how to reproduce the problem in IIS would be the trigger to have me invest more time in this. |
Multiple retries could be one solution. IMO, if we use some mutex or lock mechanism where the resource could not be reopened would help to solve the current problem. In the BookmarkFile class, if we can add a lock, then it will help if another thread is trying to access the bookmark file and will not allow it and will reduce the exceptions. This will give better handling for multi-threading errors and will still solve the purpose of a singleton. In regards to creating a sample application, let me try that and will post once I am done with it. Happy Coding :) |
Thanks! Happy coding to you as well! 😄 |
Ok, if the issue we're running into is that attempt to ship the log events overlap, I think we're in a good situation. I'll see if I can create a test for this. |
And then we should avoid throwing exceptions in this case. |
Hello, We're encountering a persistent issue on our production environment where we receive a large volume of error messages stating "The process cannot access the LogBuffer.bookmark file because it is being used by another process" during app pool recycling. Here's a summary of the problem: Error: Occurrence: Frequent during app pool recycling. Serilog.Sink.Http version: 8.0.0 Our investigation revealed: This happens according to the below steps:
Can you please implement the graceful shutdown to gracefully stop the ongoing process utilizing the logbuffer.bookmark file? |
Hi @prasadpaul53. I've started to analyze this on branch test/locked-bookmark-file. I'm creating two log event producers sharing the same buffer and bookmark file. I'm using the durable file-size rolled sink (extension method My observations are as follows:
Reflections? |
Hello @FantasticFiasco, Great that you have started the analysis.
|
The problem at heart is that we want to use the sink in two different use cases. The first one, originally in mind when creating the sink, was that the instance would terminate, and all log events ought to be sent before we terminate. That's why this line exists. The other use case, which is relevant in many of the comments in this thread, is that the instance will restart. In this context the priority is to terminate quickly, and log events can remain on file since they will be sent after the process restart. @prasadpaul53 does this sound correct? |
Yes, it is correct. @FantasticFiasco |
Release 9.0.0-beta.2 has now been published on nuget, please assert that the release fixes your issues. If it does, please report back and I'll create a new official release. Thanks for being persistent in your feedback. |
Thank you for the update on the release. We will verify the fixes and provide our feedback soon. |
Just released this as an official version, you can find it on nuget. |
Hi, We are encountering this issue where LogBuffer.bookmark is being accessed by another process. We are using version 9.0.0-beta.2 of serilog-sinks-http. Error:
We are receiving a significant number of these errors. Has there been any further improvement since version 9.0.0-beta.2 to address this scenario? Are there any configuration adjustments we should consider? |
No I don't think anything notably happened between 9.0.0-beta.2 and 9.0.0. Is your environment matching the environment of the other contributors of this issue? |
We are frequently getting below error:
Exception while emitting periodic batch from Serilog.Sinks.Http.Private.Network.HttpLogShipper: System.IO.IOException: The process cannot access the file 'F:\AuditLogs\LogBuffer.bookmark' because it is being used by another process.
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at Serilog.Sinks.Http.Private.Network.BookmarkFile..ctor(String bookmarkFileName)
at Serilog.Sinks.Http.Private.Network.HttpLogShipper.OnTick()
During the investigation, we found the post about setting bufferFileShared to True. However, this doesn't work.
Could you please suggest a fix to this issue?
The text was updated successfully, but these errors were encountered: