Staticcheck (#464)

Using `go get -u honnef.co/go/tools/cmd/staticcheck`
Uneaarthed a couple of real bugs
This commit is contained in:
Raja Subramanian
2022-02-25 12:04:08 +05:30
committed by GitHub
parent 5a4181b581
commit 0170cc1cb6
19 changed files with 32 additions and 41 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ type CongestionControlProbeMode string
const ( const (
CongestionControlProbeModePadding CongestionControlProbeMode = "padding" CongestionControlProbeModePadding CongestionControlProbeMode = "padding"
CongestionControlProbeModeMedia = "media" CongestionControlProbeModeMedia CongestionControlProbeMode = "media"
) )
type Config struct { type Config struct {
+1 -1
View File
@@ -457,7 +457,7 @@ func (r *RedisRouter) handleRTCMessage(rm *livekit.RTCNodeMessage) error {
} }
case *livekit.RTCNodeMessage_KeepAlive: case *livekit.RTCNodeMessage_KeepAlive:
if time.Now().Sub(time.Unix(rm.SenderTime, 0)) > statsUpdateInterval { if time.Since(time.Unix(rm.SenderTime, 0)) > statsUpdateInterval {
logger.Infow("keep alive too old, skipping", "senderTime", rm.SenderTime) logger.Infow("keep alive too old, skipping", "senderTime", rm.SenderTime)
break break
} }
-2
View File
@@ -29,8 +29,6 @@ type MediaTrack struct {
audioLevelMu sync.RWMutex audioLevelMu sync.RWMutex
audioLevel *AudioLevel audioLevel *AudioLevel
done chan struct{}
*MediaTrackReceiver *MediaTrackReceiver
lock sync.RWMutex lock sync.RWMutex
-3
View File
@@ -81,9 +81,6 @@ type ParticipantImpl struct {
// when first connected // when first connected
connectedAt time.Time connectedAt time.Time
// JSON encoded metadata to pass to clients
metadata string
rtcpCh chan []rtcp.Packet rtcpCh chan []rtcp.Packet
// hold reference for MediaTrack // hold reference for MediaTrack
+2 -2
View File
@@ -139,7 +139,7 @@ func (s *RedisStore) LockRoom(_ context.Context, name livekit.RoomName, duration
} }
// stop waiting past lock duration // stop waiting past lock duration
if time.Now().Sub(startTime) > duration { if time.Since(startTime) > duration {
break break
} }
@@ -282,7 +282,7 @@ func (s *RedisStore) ListEgress(_ context.Context, roomID livekit.RoomID) ([]*li
return nil, err return nil, err
} }
data, err := s.rc.HMGet(s.ctx, EgressKey, ids...).Result() data, _ := s.rc.HMGet(s.ctx, EgressKey, ids...).Result()
for _, d := range data { for _, d := range data {
if d == nil { if d == nil {
continue continue
+2 -2
View File
@@ -40,7 +40,7 @@ func TestCreateRoom(t *testing.T) {
node.Stats.NumTracksIn = 100 node.Stats.NumTracksIn = 100
node.Stats.NumTracksOut = 100 node.Stats.NumTracksOut = 100
ra, conf := newTestRoomAllocator(t, conf, node) ra, _ := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"}) _, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached) require.ErrorIs(t, err, routing.ErrNodeLimitReached)
@@ -56,7 +56,7 @@ func TestCreateRoom(t *testing.T) {
node.Stats.BytesInPerSec = 1000 node.Stats.BytesInPerSec = 1000
node.Stats.BytesOutPerSec = 1000 node.Stats.BytesOutPerSec = 1000
ra, conf := newTestRoomAllocator(t, conf, node) ra, _ := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"}) _, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached) require.ErrorIs(t, err, routing.ErrNodeLimitReached)
+1 -1
View File
@@ -381,7 +381,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
return return
} }
if time.Now().Sub(lastTokenUpdate) > tokenRefreshInterval { if time.Since(lastTokenUpdate) > tokenRefreshInterval {
pLogger.Debugw("refreshing client token after interval") pLogger.Debugw("refreshing client token after interval")
// refresh token with the first API Key/secret pair // refresh token with the first API Key/secret pair
if err := r.refreshToken(participant); err != nil { if err := r.refreshToken(participant); err != nil {
+1 -1
View File
@@ -96,7 +96,7 @@ func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.Partic
// this is new connection for existing participant - with publish only permissions // this is new connection for existing participant - with publish only permissions
if publishParam != "" { if publishParam != "" {
// Make sure grant has CanPublish set, // Make sure grant has CanPublish set,
if claims.Video.CanPublish != nil && *claims.Video.CanPublish == false { if claims.Video.CanPublish != nil && !*claims.Video.CanPublish {
return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied
} }
// Make sure by default subscribe is off // Make sure by default subscribe is off
+1 -1
View File
@@ -279,7 +279,7 @@ func (s *LivekitServer) healthCheck(w http.ResponseWriter, _ *http.Request) {
if s.Node().Stats != nil { if s.Node().Stats != nil {
updatedAt = time.Unix(s.Node().Stats.UpdatedAt, 0) updatedAt = time.Unix(s.Node().Stats.UpdatedAt, 0)
} }
if time.Now().Sub(updatedAt) > 4*time.Second { if time.Since(updatedAt) > 4*time.Second {
w.WriteHeader(http.StatusNotAcceptable) w.WriteHeader(http.StatusNotAcceptable)
_, _ = w.Write([]byte(fmt.Sprintf("Not Ready\nNode Updated At %s", updatedAt))) _, _ = w.Write([]byte(fmt.Sprintf("Not Ready\nNode Updated At %s", updatedAt)))
return return
-1
View File
@@ -147,7 +147,6 @@ func TestNack(t *testing.T) {
func TestNewBuffer(t *testing.T) { func TestNewBuffer(t *testing.T) {
type args struct { type args struct {
options Options options Options
ssrc uint32
} }
tests := []struct { tests := []struct {
name string name string
+1 -1
View File
@@ -136,7 +136,7 @@ func (n *nack) getNack(now time.Time, rtt uint32) (shouldSend bool, shouldRemove
var requiredInterval time.Duration var requiredInterval time.Duration
if n.tries > 0 { if n.tries > 0 {
// exponentially backoff retries, but cap maximum spacing between retries // exponentially backoff retries, but cap maximum spacing between retries
requiredInterval := maxInterval requiredInterval = maxInterval
backoffInterval := time.Duration(float64(rtt)*math.Pow(backoffFactor, float64(n.tries-1))) * time.Millisecond backoffInterval := time.Duration(float64(rtt)*math.Pow(backoffFactor, float64(n.tries-1))) * time.Millisecond
if backoffInterval < requiredInterval { if backoffInterval < requiredInterval {
requiredInterval = backoffInterval requiredInterval = backoffInterval
+1 -1
View File
@@ -120,7 +120,7 @@ func (cs *ConnectionStats) updateScore() float32 {
maxRTT := uint32(0) maxRTT := uint32(0)
maxJitter := uint32(0) maxJitter := uint32(0)
for _, qw := range cs.qualityWindows { for _, qw := range cs.qualityWindows {
expectedPacketsInInterval += qw.endSeqNum - qw.endSeqNum + 1 expectedPacketsInInterval += qw.endSeqNum - qw.startSeqNum + 1
lostPacketsInInterval += qw.endPacketsLost - qw.startPacketsLost lostPacketsInInterval += qw.endPacketsLost - qw.startPacketsLost
if qw.maxRTT > maxRTT { if qw.maxRTT > maxRTT {
maxRTT = qw.maxRTT maxRTT = qw.maxRTT
+9 -9
View File
@@ -984,7 +984,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678, SSRC: 0x12345678,
PayloadSize: 20, PayloadSize: 20,
} }
extPkt, err := testutils.GetTestExtPacket(params) extPkt, _ := testutils.GetTestExtPacket(params)
// should lock onto the first packet // should lock onto the first packet
expectedTP := TranslationParams{ expectedTP := TranslationParams{
@@ -1015,7 +1015,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678, SSRC: 0x12345678,
PayloadSize: 20, PayloadSize: 20,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
shouldDrop: true, shouldDrop: true,
@@ -1032,7 +1032,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
Timestamp: 0xabcdef, Timestamp: 0xabcdef,
SSRC: 0x12345678, SSRC: 0x12345678,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
shouldDrop: true, shouldDrop: true,
@@ -1049,7 +1049,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678, SSRC: 0x12345678,
PayloadSize: 20, PayloadSize: 20,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{ rtp: &TranslationParamsRTP{
@@ -1069,7 +1069,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
Timestamp: 0xabcdef, Timestamp: 0xabcdef,
SSRC: 0x12345678, SSRC: 0x12345678,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{ rtp: &TranslationParamsRTP{
@@ -1090,7 +1090,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x12345678, SSRC: 0x12345678,
PayloadSize: 20, PayloadSize: 20,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{ rtp: &TranslationParamsRTP{
@@ -1111,7 +1111,7 @@ func TestForwarderGetTranslationParamsAudio(t *testing.T) {
SSRC: 0x87654321, SSRC: 0x87654321,
PayloadSize: 20, PayloadSize: 20,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{ rtp: &TranslationParamsRTP{
@@ -1387,7 +1387,7 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
Timestamp: 0xabcdef, Timestamp: 0xabcdef,
SSRC: 0x12345678, SSRC: 0x12345678,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{ rtp: &TranslationParamsRTP{
@@ -1407,7 +1407,7 @@ func TestForwarderGetTranslationParamsVideo(t *testing.T) {
Timestamp: 0xabcdef, Timestamp: 0xabcdef,
SSRC: 0x12345678, SSRC: 0x12345678,
} }
extPkt, err = testutils.GetTestExtPacket(params) extPkt, _ = testutils.GetTestExtPacket(params)
expectedTP = TranslationParams{ expectedTP = TranslationParams{
rtp: &TranslationParamsRTP{ rtp: &TranslationParamsRTP{
-1
View File
@@ -38,7 +38,6 @@ type Responder struct {
lastExtSN uint32 lastExtSN uint32
pktCtn uint8 pktCtn uint8
lastSn uint16 lastSn uint16
lastExtInfo uint16
mSSRC uint32 mSSRC uint32
sSSRC uint32 sSSRC uint32
+1 -1
View File
@@ -68,7 +68,7 @@ func RoomStarted() {
func RoomEnded(startedAt time.Time) { func RoomEnded(startedAt time.Time) {
if !startedAt.IsZero() { if !startedAt.IsZero() {
promRoomDuration.Observe(float64(time.Now().Sub(startedAt)) / float64(time.Second)) promRoomDuration.Observe(float64(time.Since(startedAt)) / float64(time.Second))
} }
promRoomTotal.Sub(1) promRoomTotal.Sub(1)
atomic.AddInt32(&atomicRoomTotal, -1) atomic.AddInt32(&atomicRoomTotal, -1)
-2
View File
@@ -287,8 +287,6 @@ func (stats *Stats) coalesce() {
// update currentStats // update currentStats
stats.curStats = &curStats stats.curStats = &curStats
return
} }
// find delta between curStats and prevStats and prepare proto payload // find delta between curStats and prevStats and prepare proto payload
+1 -1
View File
@@ -717,7 +717,7 @@ func (c *RTCClient) processTrack(track *webrtc.TrackRemote) {
c.bytesReceived[pId] += uint64(pkt.MarshalSize()) c.bytesReceived[pId] += uint64(pkt.MarshalSize())
c.lock.Unlock() c.lock.Unlock()
numBytes += pkt.MarshalSize() numBytes += pkt.MarshalSize()
if time.Now().Sub(lastUpdate) > 30*time.Second { if time.Since(lastUpdate) > 30*time.Second {
logger.Infow("consumed from participant", logger.Infow("consumed from participant",
"track", trackId, "pID", pId, "track", trackId, "pID", pId,
"size", numBytes) "size", numBytes)
+1 -1
View File
@@ -96,7 +96,7 @@ func (w *TrackWriter) writeNull() {
w.track.WriteSample(sample) w.track.WriteSample(sample)
} }
case <-w.ctx.Done(): case <-w.ctx.Done():
break return
} }
} }
} }
+1 -1
View File
@@ -185,7 +185,7 @@ func TestMultiNodeRefreshToken(t *testing.T) {
grants, err := verifier.Verify(testApiSecret) grants, err := verifier.Verify(testApiSecret)
require.NoError(t, err) require.NoError(t, err)
if "metadata" != grants.Metadata { if grants.Metadata != "metadata" {
return "metadata did not match" return "metadata did not match"
} }
if *grants.Video.CanPublish { if *grants.Video.CanPublish {