File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -1253,11 +1253,18 @@ func (r *Request) TraceInfo() TraceInfo {
1253
1253
1254
1254
// Calculate the total time accordingly,
1255
1255
// when connection is reused
1256
+ var requestStartTime time.Time
1256
1257
if ct .gotConnInfo .Reused {
1257
- ti . TotalTime = ct .endTime . Sub ( ct . getConn )
1258
+ requestStartTime = ct .getConn
1258
1259
} else {
1259
- ti . TotalTime = ct .endTime . Sub ( ct . dnsStart )
1260
+ requestStartTime = ct .dnsStart
1260
1261
}
1262
+ // DNS start and get conn time may be zero if the request is invalid.
1263
+ // See issue #1016.
1264
+ if requestStartTime .IsZero () {
1265
+ requestStartTime = r .Time
1266
+ }
1267
+ ti .TotalTime = ct .endTime .Sub (requestStartTime )
1261
1268
1262
1269
// Only calculate on successful connections
1263
1270
if ! ct .connectDone .IsZero () {
Original file line number Diff line number Diff line change @@ -1830,6 +1830,18 @@ func TestTraceInfo(t *testing.T) {
1830
1830
1831
1831
})
1832
1832
1833
+ t .Run ("enable trace on invalid request, issue #1016" , func (t * testing.T ) {
1834
+ resp , err := client .R ().EnableTrace ().Get ("unknown://url.com" )
1835
+ assertNotNil (t , err )
1836
+ tr := resp .Request .TraceInfo ()
1837
+ assertEqual (t , true , tr .DNSLookup == 0 )
1838
+ assertEqual (t , true , tr .ConnTime == 0 )
1839
+ assertEqual (t , true , tr .TLSHandshake == 0 )
1840
+ assertEqual (t , true , tr .ServerTime == 0 )
1841
+ assertEqual (t , true , tr .ResponseTime == 0 )
1842
+ assertEqual (t , true , tr .TotalTime > 0 && tr .TotalTime < time .Second )
1843
+ })
1844
+
1833
1845
t .Run ("enable trace and debug on request" , func (t * testing.T ) {
1834
1846
c , logBuf := dcldb ()
1835
1847
c .SetBaseURL (ts .URL )
You can’t perform that action at this time.
0 commit comments