<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Valentin Berea</title>
    <description>The latest articles on DEV Community by Valentin Berea (@valy_berea).</description>
    <link>https://dev.to/valy_berea</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F292524%2Fcd8148e8-b5d4-4110-b822-274ca3b02dab.jpg</url>
      <title>DEV Community: Valentin Berea</title>
      <link>https://dev.to/valy_berea</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/valy_berea"/>
    <language>en</language>
    <item>
      <title>Debug a GitHub webhook that never reaches localhost</title>
      <dc:creator>Valentin Berea</dc:creator>
      <pubDate>Wed, 11 Nov 2026 21:39:24 +0000</pubDate>
      <link>https://dev.to/valy_berea/debug-a-github-webhook-that-never-reaches-localhost-cp4</link>
      <guid>https://dev.to/valy_berea/debug-a-github-webhook-that-never-reaches-localhost-cp4</guid>
      <description>&lt;p&gt;You're building a webhook handler. It runs on &lt;code&gt;localhost:3000&lt;/code&gt;. GitHub needs a public HTTPS address to send to, so the delivery never arrives, and you're writing your handler against the JSON sample in the docs instead of what GitHub really sends.&lt;/p&gt;

&lt;p&gt;Here's a way to get the real delivery onto your machine, headers and body intact, without a tunnel and without installing anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Get a public address that records everything
&lt;/h2&gt;

&lt;p&gt;Open &lt;a href="https://curler.dev" rel="noopener noreferrer"&gt;curler.dev&lt;/a&gt; and click &lt;strong&gt;Create a bin&lt;/strong&gt;. The top bar shows a capture URL like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://api.curler.dev/h/fZU_aI73r6LZkEr4eThskAPiWwXaXa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anything sent to that address, or to any path below it, is recorded: method, path, headers and the raw body.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Point GitHub at it
&lt;/h2&gt;

&lt;p&gt;In your repository, open &lt;strong&gt;Settings → Webhooks → Add webhook&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Payload URL:&lt;/strong&gt; the capture URL, plus a path if your handler uses one, for example &lt;code&gt;https://api.curler.dev/h/&amp;lt;your-bin&amp;gt;/webhooks/github&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content type:&lt;/strong&gt; &lt;code&gt;application/json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secret:&lt;/strong&gt; the same secret your handler checks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Save, then push a commit. The delivery shows up in the bin within a couple of seconds. Click it to see every header GitHub sent (&lt;code&gt;X-GitHub-Event&lt;/code&gt;, &lt;code&gt;X-GitHub-Delivery&lt;/code&gt;, &lt;code&gt;X-Hub-Signature-256&lt;/code&gt;) and the body as a JSON tree.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Replay it against localhost
&lt;/h2&gt;

&lt;p&gt;Under the request, set &lt;strong&gt;replay target&lt;/strong&gt; to your app's address, for example &lt;code&gt;http://localhost:3000&lt;/code&gt;, and copy the Bash command. It comes as one line; here it is shortened and wrapped for reading:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s'&lt;/span&gt; &lt;span class="s1"&gt;'{"ref":"refs/heads/main","repository":{"full_name":"octo/demo"},...}'&lt;/span&gt; \
  &lt;span class="o"&gt;|&lt;/span&gt; curl --globoff -X &lt;span class="s1"&gt;'POST'&lt;/span&gt; &lt;span class="s1"&gt;'http://localhost:3000/webhooks/github'&lt;/span&gt; \
    -H &lt;span class="s1"&gt;'User-Agent: GitHub-Hookshot/…'&lt;/span&gt; \
    -H &lt;span class="s1"&gt;'Content-Type: application/json'&lt;/span&gt; \
    -H &lt;span class="s1"&gt;'X-Github-Delivery: 72d3162e-cc78-11e3-81ab-4c9367dc0958'&lt;/span&gt; \
    -H &lt;span class="s1"&gt;'X-Github-Event: push'&lt;/span&gt; \
    -H &lt;span class="s1"&gt;'X-Hub-Signature-256: sha256=…'&lt;/span&gt; \
    --data-binary @-
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste it in a terminal and your handler receives the same request GitHub sent. Run it again as often as you like while you fix your code: set a breakpoint, change a line, replay.&lt;/p&gt;

&lt;p&gt;There's a PowerShell version next to it for Windows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the body has to be byte for byte
&lt;/h2&gt;

&lt;p&gt;GitHub signs the raw body with your secret, and your handler checks &lt;code&gt;X-Hub-Signature-256&lt;/code&gt; against the bytes it receives. One changed space, a re-ordered key or a different line ending, and the check fails.&lt;/p&gt;

&lt;p&gt;Curler stores the body exactly as it arrived, and the copied command sends it back byte for byte. A binary body goes through base64 so the shell can't alter it. So the signature check in your handler passes on a replay, exactly as it would on a live delivery.&lt;/p&gt;

&lt;h2&gt;
  
  
  When it's not GitHub
&lt;/h2&gt;

&lt;p&gt;The same steps work for any sender that needs a public URL: Stripe, Shopify, Slack, or the callback of an SSO provider such as Okta or Auth0. For a login callback, Curler shows you the exact query string or form post the provider sent, which is usually where the reason for a failed login hides.&lt;/p&gt;

&lt;h2&gt;
  
  
  Good to know
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Curler is free: a bin lives 24 hours and keeps its newest 100 requests.&lt;/li&gt;
&lt;li&gt;The bin's page updates on its own while it's open, so you can leave it next to your editor.&lt;/li&gt;
&lt;li&gt;Curler's server sleeps when nobody uses it, and the first call after a quiet spell can take about 10 seconds. GitHub waits 10 seconds for an answer, so open your bin's page before you trigger the first delivery. If one is missed, &lt;strong&gt;Redeliver&lt;/strong&gt; on GitHub's webhook page sends it again.&lt;/li&gt;
&lt;li&gt;Captured content is never rendered as HTML, so a hostile payload can't run in your browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm the developer of Curler. If something about your webhook didn't show up the way you expected, tell me: &lt;a href="mailto:feedback@curler.dev"&gt;feedback@curler.dev&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>webhooks</category>
      <category>github</category>
      <category>debugging</category>
    </item>
    <item>
      <title>Test your Polly retry policy against a real failing server</title>
      <dc:creator>Valentin Berea</dc:creator>
      <pubDate>Tue, 10 Nov 2026 22:21:36 +0000</pubDate>
      <link>https://dev.to/valy_berea/test-your-polly-retry-policy-against-a-real-failing-server-5a9e</link>
      <guid>https://dev.to/valy_berea/test-your-polly-retry-policy-against-a-real-failing-server-5a9e</guid>
      <description>&lt;p&gt;Most retry policies are tested in one of two ways: not at all, or with a mocked &lt;code&gt;HttpMessageHandler&lt;/code&gt; that throws on cue. The mock proves that Polly calls your delegate again. It doesn't show what your app does when a real server is slow, answers &lt;code&gt;503&lt;/code&gt; twice, then takes three seconds to say yes.&lt;/p&gt;

&lt;p&gt;Here's a way to see that in about five minutes, with no change to your app except the URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup: a server that fails on purpose
&lt;/h2&gt;

&lt;p&gt;I built &lt;a href="https://curler.dev" rel="noopener noreferrer"&gt;Curler&lt;/a&gt; for this. You create a bin, give it a script of responses, and point your app at the bin's URL. Every call your app makes shows up with the response Curler sent, when it was sent and how long it took.&lt;/p&gt;

&lt;p&gt;The script for this post:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"steps"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"times"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"delayMs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"contentType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{\"paid\":true}"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two &lt;code&gt;503&lt;/code&gt;s, then a &lt;code&gt;200&lt;/code&gt; that takes three seconds. The last step repeats, so every call after the second gets the slow success. This is a payment provider on a bad day.&lt;/p&gt;

&lt;p&gt;To use it: open &lt;a href="https://curler.dev" rel="noopener noreferrer"&gt;curler.dev&lt;/a&gt;, click &lt;strong&gt;Create a bin&lt;/strong&gt;, click &lt;strong&gt;Edit&lt;/strong&gt; in the Responses bar, paste the script and save. Copy the capture URL from the top bar.&lt;/p&gt;

&lt;h2&gt;
  
  
  The app
&lt;/h2&gt;

&lt;p&gt;A console app with Polly v8. It retries server errors and timeouts three times, with exponential backoff, and gives each attempt 2 seconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Diagnostics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Polly&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Polly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Retry&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Polly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Timeout&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;attemptTimeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;clock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartNew&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ResiliencePipelineBuilder&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;HttpResponseMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RetryStrategyOptions&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;HttpResponseMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;ShouldHandle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PredicateBuilder&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;HttpResponseMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Handle&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;HttpRequestException&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Handle&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TimeoutRejectedException&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HandleResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StatusCode&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;MaxRetryAttempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;BackoffType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DelayBackoffType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Exponential&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;OnRetry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;why&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Outcome&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StatusCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="n"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Outcome&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{clock.Elapsed.TotalSeconds,5:0.0}s  attempt {retry.AttemptNumber + 1} failed ({why}), retrying in {retry.RetryDelay.TotalSeconds:0.0}s"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attemptTimeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// added after the retry, so it applies to each attempt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ExecuteAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PostAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StringContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{\"orderId\":42}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{clock.Elapsed.TotalSeconds,5:0.0}s  done: {(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{clock.Elapsed.TotalSeconds,5:0.0}s  gave up: {exception.GetType().Name}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The order matters. In Polly v8 the first strategy you add is the outermost, so the retry wraps the timeout, and the timeout applies to each attempt rather than to the whole call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run 1: a 2-second timeout per attempt
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ dotnet run -- https://api.curler.dev/h/&amp;lt;your-bin&amp;gt; 2
  0.8s  attempt 1 failed (ServiceUnavailable), retrying in 1.0s
  1.9s  attempt 2 failed (ServiceUnavailable), retrying in 2.0s
  5.9s  attempt 3 failed (TimeoutRejectedException), retrying in 4.0s
 11.9s  gave up: TimeoutRejectedException
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server was ready to answer &lt;code&gt;200&lt;/code&gt; from the third call on. The app never saw it: each attempt gave up after 2 seconds, while the answer needed 3. After 12 seconds and four calls, the order failed.&lt;/p&gt;

&lt;p&gt;Curler's bin shows the same story from the server's side. The two slow successes are marked &lt;strong&gt;Abandoned&lt;/strong&gt;: your app hung up before Curler could answer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh8jvb8xvfp9ddf3j0pn9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh8jvb8xvfp9ddf3j0pn9.png" alt="Curler's bin: two 503s, two abandoned 200s, then the second run's 503s and the 200 that completed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the bug a mock never finds: the policy works, but its numbers don't fit the service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run 2: a 5-second timeout per attempt
&lt;/h2&gt;

&lt;p&gt;Click &lt;strong&gt;Reset counter&lt;/strong&gt; in Curler, so the script starts again from step 1, then run with 5 seconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ dotnet run -- https://api.curler.dev/h/&amp;lt;your-bin&amp;gt; 5
  0.3s  attempt 1 failed (ServiceUnavailable), retrying in 1.0s
  1.4s  attempt 2 failed (ServiceUnavailable), retrying in 2.0s
  6.5s  done: 200 {"paid":true}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two quick failures, a wait, and the slow success gets through: 1.4 s + 2.0 s of backoff + 3 s for the answer = 6.4 s.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to try next
&lt;/h2&gt;

&lt;p&gt;Change the script and watch what your policy does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A &lt;code&gt;429&lt;/code&gt; with &lt;code&gt;Retry-After: 5&lt;/code&gt;.&lt;/strong&gt; Does your retry wait the 5 seconds the server asked for, or its own backoff?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A &lt;code&gt;200&lt;/code&gt; after 10 seconds.&lt;/strong&gt; With &lt;code&gt;AddStandardResilienceHandler&lt;/code&gt; from &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt;, each attempt times out after 10 seconds by default.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A redirect.&lt;/strong&gt; Does &lt;code&gt;HttpClient&lt;/code&gt; follow it, and does the retry see the first response or the last?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Good to know
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Curler is free: a bin lives 24 hours and keeps its newest 100 requests.&lt;/li&gt;
&lt;li&gt;Curler's server sleeps when nobody uses it, and the first call after a quiet spell can take about 10 seconds. Open your bin's page before you run the app: it wakes the server, so your first attempt isn't the one that pays for the start.&lt;/li&gt;
&lt;li&gt;The script accepts JSON and plain-text bodies only, and redirects stay inside Curler, so a bin can't be used to host a phishing page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm the developer of Curler, and I'd like to hear what you'd test with it: &lt;a href="mailto:feedback@curler.dev"&gt;feedback@curler.dev&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>polly</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
