NullReferenceException in SafeTimer
Hi,
this is a support request, because i feel a little bit stupid right now.
From time to time I get a lof of exceptions like this:
"exception": {
"type": "System.NullReferenceException",
"message": "Object reference not set to an instance of an object.",
"stackTrace": " at Orleans.Runtime.InsideRuntimeClient.OnCallbackExpiryTick(Object state)\n at Orleans.Runtime.SafeTimerBase.HandleSyncTimerCallback(Object state)"
},
Which is strange, because...
-
I have disabled the logs for this category: https://github.com/Squidex/squidex/blob/master/src/Squidex/Config/Logging.cs#L26
-
I don't see how it can happen, because there is nothing in your code and this stack trace that could be null.
Usually everything works fine and I just restart the node to get rid of the log entries, but I have no idea how it can happen.
I have disabled the logs for this category: https://github.com/Squidex/squidex/blob/master/src/Squidex/Config/Logging.cs#L26
I think you didn't really disabled the category, in the config, it filters out messages under "Error" loglevel, meaning it still show message with Error level and above. This message maybe logged as an Error. Maybe this is why you are seeing it.
I don't see how it can happen, because there is nothing in your code and this stack trace that could be null.
It does look odd. I don't have an idea now either. I will need to look into more. Do you have more stack trace, such as which line it happens?
I have json logs, not very likely that it is logged as an error:
` app: {…}
category: "Orleans.Runtime.SafeTimer"
eventId: {…}
exception: {…}
logLevel: "Warning"
message: "Ignored exception Object reference not set to an instance of an object. during sync timer callback Orleans.Runtime.sync.SafeTimerBase"
timestamp: "2019-05-21T08:35:28Z"
``
hmmm weird. how do you consume the logs? are you using the legacy ILogConsumer or a ILoggerProvider which is native to the logging abstraction we use in 2.0. I ask because in legacy logger, we have to map the new logging level to legacy logging leve and vice versal, so maybe there is a bug there which mapped warning to error.
I use ILoggerProvider and a custom log sink.
It just happened again, I think it is not only about the logging but also about the root cause of this issue. Because when it happens it never stops and can prevent the whole expiration system from stopping properly.
What I was thinking about is that something could send a request through the InsideRuntimeClient before the initialization has been completed. Then it would cause the null pointer exception because the sharedCallbackData is null.
@SebastianStehle are you able to create a repro? I'm happy to take a look and try to fix it. My initial suspicion is that the delegate itself is throwing the exception, but I'm not sure what the delegate is in this case or how the timer is configured.
No, not yet, it only happens from time to time on my server. When it happens it logs the exception every second and it seems that it can probably not handle expiration times correctly. It also never stops then.
As you can see in my first post the delegate is Orleans.Runtime.InsideRuntimeClient.OnCallbackExpiryTick
@SebastianStehle my apologies. I'm taking a look
Here is a repro: https://github.com/SebastianStehle/OrleansRepro
I know that the code is not correct, but the problem is that a single error brings orleans in a difficult state and the task just hangs forever so it is hard to find the root cause, where the initialization went wrong.
Much appreciated, @SebastianStehle
I think there should be an InvalidOperationException("Orleans is not initialized yet") or so.
What I have seen in an old log is this message:
I 2019-07-18T16:29:27.860689649Z QueueWorkItem was called on a non-null context [SystemTarget: S10.0.1.88:11111:301163364*stg/14/0000000e@S0000000e] but there is no valid WorkItemGroup for it.
I 2019-07-18T16:29:27.899613556Z SelectTarget failed with QueueWorkItem was called on a non-null context [SystemTarget: S10.0.1.88:11111:301163364*stg/14/0000000e@S0000000e] but there is no valid WorkItemGroup for it.
I 2019-07-18T16:29:27.931557429Z Invalid usage attempt of Runtime.Scheduler.OrleansSchedulerAsynchAgent/Scheduler.LevelOne.SystemQueue agent in Unstarted state
I don't know what it means but it could come from the Reminders.
Good fix, but it does not solve the real problem that there is no proper error handling to prevent calls to Orleans before it is initialized.
Yes, I agree. I think we should make a separate change for that