Prevent race condition between sessions in my Fiddler Classic extension

0 Answers 65 Views
Extensions and Customization Fiddler Classic
Ben
Top achievements
Rank 1
Ben asked on 11 Aug 2021, 11:55 AM | edited on 11 Aug 2021, 05:25 PM

Hello,

I currently develop a small extension for hobbyist use. The extension reads some information of HTTP traffic between a local application and a server. This works pretty well so far but I stumbled on an issue.

I have two HTTP requests from the application to the server following each other. The first contains the last telemetry and the second requests a result of all previously sent telemetry. Without using Fiddler this works just as expected, but it seems like Fiddler adds enough delay to the first session that the application sends the second request before the server received the first. This sometimes results in the second requests reaching the server to late which means the answer to it from the server is incomplete.

I currently use a workaround by adding a delay to the second session to make it less likely to happen. But I already noticed that even 250ms is not always enough.

public void AutoTamperRequestBefore(Session oSession)
{
    switch (oSession.fullUrl)
    {
        case string s when s == Data.Version.ContractEventsUrl:

            //the first session that needs to reach the server before the second
            //some code
            break;

        case string s when s == Data.Version.ContractEndUrl:
                            
            //the second session that needs to reach the server after the first
            oSession["request-trickle-delay"] = "250";
            break;
    }
}

I noticed that the Session object can be checked if it received a response.

https://www.fiddlerbook.com/om/html/7FE52DC7.htm

I think a good solution would be to put the first session in a variable of the Main class and hold the second session until the first received an answer.

However, I noticed that adding async code to the AutoTamperRequestBefore results in the Session to fire the HTTP request the moment async code is reached. I find nothing about it in the documentation and I don't want to put the Thread to sleep to avoid that.

 

What can I do?

Greetings, Ben

Ben
Top achievements
Rank 1
commented on 11 Aug 2021, 06:20 PM | edited

In case I did something wrong I tried again with async code. As it was before, async seems to not work well with how Sessions work.

private List<Session> Events = new List<Session>(); public async void AutoTamperRequestBefore(Session oSession) { switch (oSession.fullUrl) { case string s when s == Data.Version.ContractEventsUrl: //the first session that needs to reach the server before the second Events.Add(oSession); //some code

break; case string s when s == Data.Version.ContractEndUrl: //the second session that needs to reach the server after the first

while (!Events.All(session => session.bHasResponse) { await Task.Delay(25); //does not work }

Events.Clear();

break; } }


Nick Iliev
Telerik team
commented on 12 Aug 2021, 11:38 AM

Given that you have a condition that verifies that the first session is received (e.g. a custom flag raised on successful response) you could use the session flag x-breakrequest to pause the execution.

Basic examples: https://docs.telerik.com/fiddler/knowledge-base/fiddlerscript/pausesessions#pause-web-sessions

 

Ben
Top achievements
Rank 1
commented on 23 Aug 2021, 08:24 PM

Thank you Nick that fixed my issue.

No answers yet. Maybe you can help?

Tags
Extensions and Customization Fiddler Classic
Asked by
Ben
Top achievements
Rank 1
Share this question
or