Browse Source

Fix outputRepetitiveNotice issues

- NoticeServerAlert didn't use sufficiently
  distinct repetitionKeys.

- Always emit when a repetitionKey is not
  found. Previous code appeared to work when the
  repetitionMessage was not blank, which would
  not match the zero value in a new state.
Rod Hynes 6 years ago
parent
commit
17a1b74b9f
1 changed files with 17 additions and 11 deletions
  1. 17 11
      psiphon/notice.go

+ 17 - 11
psiphon/notice.go

@@ -726,7 +726,7 @@ func NoticeLocalProxyError(proxyType string, err error) {
 	}
 	}
 
 
 	outputRepetitiveNotice(
 	outputRepetitiveNotice(
-		"LocalProxyError"+proxyType, repetitionMessage, 1,
+		"LocalProxyError-"+proxyType, repetitionMessage, 1,
 		"LocalProxyError", noticeIsDiagnostic,
 		"LocalProxyError", noticeIsDiagnostic,
 		"message", err.Error())
 		"message", err.Error())
 }
 }
@@ -867,8 +867,12 @@ func NoticeApplicationParameters(keyValues parameters.KeyValues) {
 // NoticeServerAlert reports server alerts. Each distinct server alert is
 // NoticeServerAlert reports server alerts. Each distinct server alert is
 // reported at most once per session.
 // reported at most once per session.
 func NoticeServerAlert(alert protocol.AlertRequest) {
 func NoticeServerAlert(alert protocol.AlertRequest) {
+
+	// This key ensures that each distinct server alert will appear, not repeat,
+	// and not interfere with other alerts appearing.
+	repetitionKey := fmt.Sprintf("ServerAlert-%+v", alert)
 	outputRepetitiveNotice(
 	outputRepetitiveNotice(
-		"ServerAlert", fmt.Sprintf("%+v", alert), 0,
+		repetitionKey, "", 0,
 		"ServerAlert", noticeIsDiagnostic, "reason", alert.Reason, "subject", alert.Subject)
 		"ServerAlert", noticeIsDiagnostic, "reason", alert.Reason, "subject", alert.Subject)
 }
 }
 
 
@@ -891,20 +895,22 @@ func outputRepetitiveNotice(
 	repetitiveNoticeMutex.Lock()
 	repetitiveNoticeMutex.Lock()
 	defer repetitiveNoticeMutex.Unlock()
 	defer repetitiveNoticeMutex.Unlock()
 
 
-	state, ok := repetitiveNoticeStates[repetitionKey]
-	if !ok {
+	state, keyFound := repetitiveNoticeStates[repetitionKey]
+	if !keyFound {
 		state = new(repetitiveNoticeState)
 		state = new(repetitiveNoticeState)
 		repetitiveNoticeStates[repetitionKey] = state
 		repetitiveNoticeStates[repetitionKey] = state
 	}
 	}
 
 
 	emit := true
 	emit := true
-	if repetitionMessage != state.message {
-		state.message = repetitionMessage
-		state.repeats = 0
-	} else {
-		state.repeats += 1
-		if state.repeats > repeatLimit {
-			emit = false
+	if keyFound {
+		if repetitionMessage != state.message {
+			state.message = repetitionMessage
+			state.repeats = 0
+		} else {
+			state.repeats += 1
+			if state.repeats > repeatLimit {
+				emit = false
+			}
 		}
 		}
 	}
 	}