Incomplete JSON if error happens in thread
Closed this issue · 8 comments
The issue is related to the RaygunRequestMessage.cfc component when an error occurs in a thread and cgi.LOCAL_ADDR value is undefined. This leads to incomplete JSON being sent to the Raygun API, causing errors in the dashboard.
One way to fix is to check if we are in a thread and set returnContent["data"] = {}, RaygunRequestMessage.cfc line 42
The message label in Raygun Crash Reporting dashboard says "Unexpected end of input".
To reproduce, you can run code as such:
thread action="run" name="myThread" {
var raygun = createObject("component","nz.co.ventego-creative.raygun4cfml.RaygunClient").init(
apiKey = variables.RAYGUNAPIKEY
);
try {
(1/0);
} catch(any e) {
result = raygun.send(e);
}
}
The core problem here, @gedas20, is that Adobe ColdFusion behaves really weird when it comes to threads. Unlike in Lucee, things in ACF are sometimes randomly there or not there, depending on if the page has finished by the time the thread gets into your error state. ACF will just not have CGI or Request information available then.
It's essentially a variation of this:
I would call this a bug in ACF, but evidently Adobe doesn't really see it that way.
In your ticket, you observe the problem in the CGI scope, but it might as well happen when GetHTTPRequestData()
is being called.
I think you are right about GetHTTPRequestData() call being an issue as well. cause i can see we have a fix for that locally in RaygunRequestMessage.cfc as such:
try { var httpRequest = getHttpRequestData(); } catch any (e) { var httpRequest = { headers : {}, content : "" }; }
For the cgi use we have:
var threadName = createObject("java", "java.lang.Thread").currentThread().getThreadGroup().getName(); returnContent["data"] = threadName == "cfthread" ? {} : CGI;
Not sure if something or similar could be added to the library, cause i rather not touch the library files if possible.
Thank You
@gedas20 I'm actually in the process of fixing your ticket right now :)
@gedas20 The other weird thing in ACF I found when looking into it , was this:
Note: When ColdFusion uses a connector to access the web server, after the page gets completed, the CGI and Request scopes are not accessible to threads that you create by using the cfthread tag. This limitation does not apply if you use the integrated web server or if you run ColdFusion as a J2EE application.
So, if you connect up Apache or IIS using the ACF connector libraries and don't just http proxy the requests from Apache etc then this whole behaviour is even more broken and inconsistent.
Fixed in 1.7.0
@gedas20 If you want to have a look at it before it's on Forgebox or tagged in this release, you can grab the latest from develop
in my fork: https://github.com/TheRealAgentK/raygun4cfml/tree/develop
Thank you so much. Pulled new file in, my integration test still passes. Will try actual api call to raygun from a thread maybe tomorrow.