From 05e10085b43860d77c28ce2770579d52522a1f60 Mon Sep 17 00:00:00 2001
From: huitema <huitema@huitema.net>
Date: Sun, 2 Dec 2018 22:02:21 -0800
Subject: [PATCH] Fix the congestion window after spurious retransmit.

---
 picoquic/frames.c           | 5 +++++
 picoquic/newreno.c          | 5 +++++
 picoquictest/tls_api_test.c | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/picoquic/frames.c b/picoquic/frames.c
index 3a9be3ac..b447703a 100644
--- a/picoquic/frames.c
+++ b/picoquic/frames.c
@@ -1287,6 +1287,11 @@ void picoquic_check_spurious_retransmission(picoquic_cnx_t* cnx,
                 if (max_reorder_gap > old_path->max_reorder_gap) {
                     old_path->max_reorder_gap = max_reorder_gap;
                 }
+
+                if (cnx->congestion_alg != NULL ) {
+                    cnx->congestion_alg->alg_notify(old_path, picoquic_congestion_notification_spurious_repeat,
+                        0, 0, p->sequence_number, current_time);
+                }
             }
 
             cnx->nb_spurious++;
diff --git a/picoquic/newreno.c b/picoquic/newreno.c
index 01ffa05f..e5c3ae24 100644
--- a/picoquic/newreno.c
+++ b/picoquic/newreno.c
@@ -110,6 +110,11 @@ void picoquic_newreno_notify(picoquic_path_t* path_x,
                 picoquic_newreno_enter_recovery(path_x, notification, nr_state, current_time);
                 break;
             case picoquic_congestion_notification_spurious_repeat:
+                /* Immediately exit the previous recovery */
+                if (path_x->cwin < 2 * nr_state->ssthresh) {
+                    path_x->cwin = 2 * nr_state->ssthresh;
+                    nr_state->alg_state = picoquic_newreno_alg_congestion_avoidance;
+                }
                 break;
             case picoquic_congestion_notification_rtt_measurement:
                 /* TODO: consider using RTT increases as signal to get out of slow start */
diff --git a/picoquictest/tls_api_test.c b/picoquictest/tls_api_test.c
index ba8b0bb6..3a368b58 100644
--- a/picoquictest/tls_api_test.c
+++ b/picoquictest/tls_api_test.c
@@ -1416,7 +1416,7 @@ int tls_api_very_long_max_test()
 
 int tls_api_very_long_with_err_test()
 {
-    return tls_api_one_scenario_test(test_scenario_very_long, sizeof(test_scenario_very_long), 0x30000, 128000, 0, 0, 5000000, NULL, NULL);
+    return tls_api_one_scenario_test(test_scenario_very_long, sizeof(test_scenario_very_long), 0x30000, 128000, 0, 0, 4000000, NULL, NULL);
 }
 
 int tls_api_very_long_congestion_test()
-- 
GitLab