Repository: pion/dtls
Pull request #210 (2020-03-05 11:35:21)

Limit retransmit interval of last flight
Also fix retransmit interval parameter in TestHandshaker. It sometimes caused WASM test failure.


codecov[bot]: # [Codecov](https://codecov.io/gh/pion/dtls/pull/210?src=pr&el=h1) Report
> Merging [#210](https://codecov.io/gh/pion/dtls/pull/210?src=pr&el=desc) into [master](https://codecov.io/gh/pion/dtls/commit/3b0a286c52a17f9adab20bf15b493e1c28a9b609?src=pr&el=desc) will **decrease** coverage by `0.08%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pion/dtls/pull/210/graphs/tree.svg?width=650&token=bcCB2jB88I&height=150&src=pr)](https://codecov.io/gh/pion/dtls/pull/210?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #210      +/-   ##
==========================================
- Coverage   77.23%   77.15%   -0.09%     
==========================================
  Files          73       73              
  Lines        3963     3965       +2     
==========================================
- Hits         3061     3059       -2     
- Misses        612      615       +3     
- Partials      290      291       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #go | `77.15% <100%> (-0.09%)` | :arrow_down: |
| #wasm | `?` | |

| [Impacted Files](https://codecov.io/gh/pion/dtls/pull/210?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [handshaker.go](https://codecov.io/gh/pion/dtls/pull/210/diff?src=pr&el=tree#diff-aGFuZHNoYWtlci5nbw==) | `75.69% <100%> (+0.34%)` | :arrow_up: |
| [internal/net/deadline/deadline.go](https://codecov.io/gh/pion/dtls/pull/210/diff?src=pr&el=tree#diff-aW50ZXJuYWwvbmV0L2RlYWRsaW5lL2RlYWRsaW5lLmdv) | `82.45% <0%> (-3.51%)` | :arrow_down: |
| [internal/net/dpipe/dpipe.go](https://codecov.io/gh/pion/dtls/pull/210/diff?src=pr&el=tree#diff-aW50ZXJuYWwvbmV0L2RwaXBlL2RwaXBlLmdv) | `94.11% <0%> (-2.36%)` | :arrow_down: |
| [internal/net/udp/conn.go](https://codecov.io/gh/pion/dtls/pull/210/diff?src=pr&el=tree#diff-aW50ZXJuYWwvbmV0L3VkcC9jb25uLmdv) | `85.15% <0%> (-1.57%)` | :arrow_down: |
| [conn.go](https://codecov.io/gh/pion/dtls/pull/210/diff?src=pr&el=tree#diff-Y29ubi5nbw==) | `85.26% <0%> (+0.37%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/dtls/pull/210?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/dtls/pull/210?src=pr&el=footer). Last update [3b0a286...3368aa7](https://codecov.io/gh/pion/dtls/pull/210?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/handshaker.go b/handshaker.go
index 748dcd5..72e4b3d 100644
--- a/handshaker.go
+++ b/handshaker.go
@@ -283,6 +283,7 @@ func (s *handshakeFSM) finish(ctx context.Context, c flightConn) (handshakeState
 		return handshakeErrored, errFlight
 	}
 
+	retransmitTimer := time.NewTimer(s.cfg.retransmitInterval)
 	select {
 	case done := <-c.recvHandshake():
 		nextFlight, alert, err := parse(ctx, c, s.state, s.cache, s.cfg)
@@ -300,6 +301,7 @@ func (s *handshakeFSM) finish(ctx context.Context, c flightConn) (handshakeState
 		if nextFlight == 0 {
 			break
 		}
+		<-retransmitTimer.C
 		// Retransmit last flight
 		return handshakeSending, nil
 


Test patch:
diff --git a/handshaker_test.go b/handshaker_test.go
index 0062362..ac57f53 100644
--- a/handshaker_test.go
+++ b/handshaker_test.go
@@ -12,6 +12,8 @@ import (
 	"github.com/pion/transport/test"
 )
 
+const nonZeroRetransmitInterval = 100 * time.Millisecond
+
 func TestHandshaker(t *testing.T) {
 	// Check for leaking routines
 	report := test.CheckRoutines(t)
@@ -37,6 +39,7 @@ func TestHandshaker(t *testing.T) {
 
 	var wg sync.WaitGroup
 	wg.Add(2)
+
 	ctxCliFinished, cancelCli := context.WithCancel(ctx)
 	ctxSrvFinished, cancelSrv := context.WithCancel(ctx)
 	go func() {
@@ -51,6 +54,7 @@ func TestHandshaker(t *testing.T) {
 					cancelCli()
 				}
 			},
+			retransmitInterval: nonZeroRetransmitInterval,
 		}
 
 		fsm := newHandshakeFSM(&ca.state, ca.handshakeCache, cfg, flight1)