-
Notifications
You must be signed in to change notification settings - Fork 0
Fix pre-existing lint issues (partial) #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
943a4fc
774c111
440f0d7
6539eff
4020962
a050efe
a86142f
136e94d
0cc3ebf
081e2b6
3960b59
7a32584
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ import ( | |
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "io" | ||
| "net" | ||
| "net/http" | ||
| "strings" | ||
|
|
@@ -87,9 +87,9 @@ func readResponse(res *http.Response, err error) ([]byte, error) { | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer res.Body.Close() | ||
| defer func() { _ = res.Body.Close() }() | ||
|
|
||
| body, err := ioutil.ReadAll(res.Body) | ||
| body, err := io.ReadAll(res.Body) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -120,7 +120,7 @@ func SubmitAgent(hostname string, port int, token string) (string, error) { | |
| } | ||
|
|
||
| // Try to discover topology instances when an agent submits | ||
| go DiscoverAgentInstance(hostname, port) | ||
| go func() { _ = DiscoverAgentInstance(hostname, port) }() | ||
|
|
||
| return hostname, err | ||
| } | ||
|
|
@@ -129,18 +129,18 @@ func SubmitAgent(hostname string, port int, token string) (string, error) { | |
| func DiscoverAgentInstance(hostname string, port int) error { | ||
| agent, err := GetAgent(hostname) | ||
| if err != nil { | ||
| log.Errorf("Couldn't get agent for %s: %v", hostname, err) | ||
| _ = log.Errorf("Couldn't get agent for %s: %v", hostname, err) | ||
| return err | ||
| } | ||
|
|
||
| instanceKey := agent.GetInstance() | ||
| instance, err := inst.ReadTopologyInstance(instanceKey) | ||
| if err != nil { | ||
| log.Errorf("Failed to read topology for %v. err=%+v", instanceKey, err) | ||
| _ = log.Errorf("Failed to read topology for %v. err=%+v", instanceKey, err) | ||
| return err | ||
| } | ||
| if instance == nil { | ||
| log.Errorf("Failed to read topology for %v", instanceKey) | ||
| _ = log.Errorf("Failed to read topology for %v", instanceKey) | ||
| return err | ||
| } | ||
| log.Infof("Discovered Agent Instance: %v", instance.Key) | ||
|
|
@@ -177,7 +177,7 @@ func ReadOutdatedAgentsHosts() ([]string, error) { | |
| }) | ||
|
|
||
| if err != nil { | ||
| log.Errore(err) | ||
| _ = log.Errore(err) | ||
| } | ||
| return res, err | ||
| } | ||
|
|
@@ -210,7 +210,7 @@ func ReadAgents() ([]Agent, error) { | |
| }) | ||
|
|
||
| if err != nil { | ||
| log.Errore(err) | ||
| _ = log.Errore(err) | ||
| } | ||
| return res, err | ||
|
|
||
|
|
@@ -322,7 +322,7 @@ func GetAgent(hostname string) (Agent, error) { | |
| err = json.Unmarshal(body, &agent.AvailableLocalSnapshots) | ||
| } | ||
| if err != nil { | ||
| log.Errore(err) | ||
| _ = log.Errore(err) | ||
| } | ||
| } | ||
| { | ||
|
|
@@ -359,7 +359,7 @@ func GetAgent(hostname string) (Agent, error) { | |
| mySQLRunningUri := fmt.Sprintf("%s/mysql-status?token=%s", uri, token) | ||
| body, err := readResponse(httpGet(mySQLRunningUri)) | ||
| if err == nil { | ||
| err = json.Unmarshal(body, &agent.MySQLRunning) | ||
| _ = json.Unmarshal(body, &agent.MySQLRunning) | ||
| } | ||
| // Actually an error is OK here since "status" returns with non-zero exit code when MySQL not running | ||
| } | ||
|
|
@@ -434,7 +434,7 @@ func executeAgentCommandWithMethodFunc(hostname string, command string, methodFu | |
| if onResponse != nil { | ||
| (*onResponse)(body) | ||
| } | ||
| auditAgentOperation("agent-command", &agent, command) | ||
| _ = auditAgentOperation("agent-command", &agent, command) | ||
|
|
||
| return agent, err | ||
| } | ||
|
|
@@ -519,7 +519,7 @@ func CustomCommand(hostname string, cmd string) (output string, err error) { | |
| func seedCommandCompleted(hostname string, seedId int64) (Agent, bool, error) { | ||
| result := false | ||
| onResponse := func(body []byte) { | ||
| json.Unmarshal(body, &result) | ||
| _ = json.Unmarshal(body, &result) | ||
| } | ||
| agent, err := executeAgentCommand(hostname, fmt.Sprintf("seed-command-completed/%d", seedId), &onResponse) | ||
| return agent, result, err | ||
|
|
@@ -529,7 +529,7 @@ func seedCommandCompleted(hostname string, seedId int64) (Agent, bool, error) { | |
| func seedCommandSucceeded(hostname string, seedId int64) (Agent, bool, error) { | ||
| result := false | ||
| onResponse := func(body []byte) { | ||
| json.Unmarshal(body, &result) | ||
| _ = json.Unmarshal(body, &result) | ||
| } | ||
| agent, err := executeAgentCommand(hostname, fmt.Sprintf("seed-command-succeeded/%d", seedId), &onResponse) | ||
| return agent, result, err | ||
|
|
@@ -543,7 +543,7 @@ func AbortSeed(seedId int64) error { | |
| } | ||
|
|
||
| for _, seedOperation := range seedOperations { | ||
| AbortSeedCommand(seedOperation.TargetHostname, seedId) | ||
| _, _ = AbortSeedCommand(seedOperation.TargetHostname, seedId) | ||
| AbortSeedCommand(seedOperation.SourceHostname, seedId) | ||
| } | ||
| updateSeedComplete(seedId, errors.New("Aborted")) | ||
|
Comment on lines
545
to
549
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't mark the seed aborted when the abort RPCs are unchecked. This loop discards both agent-side abort results and then unconditionally marks the seed as aborted on Line 549. If either agent misses the abort, orchestrator can report success while the copy is still running. Proposed fix func AbortSeed(seedId int64) error {
seedOperations, err := AgentSeedDetails(seedId)
if err != nil {
return log.Errore(err)
}
+ var abortErr error
for _, seedOperation := range seedOperations {
- _, _ = AbortSeedCommand(seedOperation.TargetHostname, seedId)
- AbortSeedCommand(seedOperation.SourceHostname, seedId)
+ if _, err := AbortSeedCommand(seedOperation.TargetHostname, seedId); err != nil && abortErr == nil {
+ abortErr = err
+ }
+ if _, err := AbortSeedCommand(seedOperation.SourceHostname, seedId); err != nil && abortErr == nil {
+ abortErr = err
+ }
}
+ if abortErr != nil {
+ return log.Errore(abortErr)
+ }
updateSeedComplete(seedId, errors.New("Aborted"))
return nil
}🤖 Prompt for AI Agents |
||
|
|
@@ -702,8 +702,8 @@ func executeSeed(seedId int64, targetHostname string, sourceHostname string) err | |
| if err != nil { | ||
| return updateSeedStateEntry(seedStateId, err) | ||
| } | ||
| sourceAgent, err = GetAgent(sourceHostname) | ||
| seedStateId, _ = submitSeedStateEntry(seedId, fmt.Sprintf("MySQL data volume on source host %s is %d bytes", sourceHostname, sourceAgent.MountPoint.MySQLDiskUsage), "") | ||
| sourceAgent, _ = GetAgent(sourceHostname) | ||
| _, _ = submitSeedStateEntry(seedId, fmt.Sprintf("MySQL data volume on source host %s is %d bytes", sourceHostname, sourceAgent.MountPoint.MySQLDiskUsage), "") | ||
|
Comment on lines
+705
to
+706
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the If this refresh fails, Proposed fix- sourceAgent, _ = GetAgent(sourceHostname)
- _, _ = submitSeedStateEntry(seedId, fmt.Sprintf("MySQL data volume on source host %s is %d bytes", sourceHostname, sourceAgent.MountPoint.MySQLDiskUsage), "")
+ sourceAgent, err = GetAgent(sourceHostname)
+ if err != nil {
+ _, _ = Unmount(sourceHostname)
+ return updateSeedStateEntry(seedStateId, err)
+ }
+ _, _ = submitSeedStateEntry(seedId, fmt.Sprintf("MySQL data volume on source host %s is %d bytes", sourceHostname, sourceAgent.MountPoint.MySQLDiskUsage), "")🤖 Prompt for AI Agents |
||
|
|
||
| seedStateId, _ = submitSeedStateEntry(seedId, fmt.Sprintf("Erasing MySQL data on %s", targetHostname), "") | ||
| _, err = deleteMySQLDatadir(targetHostname) | ||
|
|
@@ -719,14 +719,14 @@ func executeSeed(seedId int64, targetHostname string, sourceHostname string) err | |
|
|
||
| if sourceAgent.MountPoint.MySQLDiskUsage > targetAgent.MySQLDatadirDiskFree { | ||
| Unmount(sourceHostname) | ||
| return updateSeedStateEntry(seedStateId, fmt.Errorf("Not enough disk space on target host %s. Required: %d, available: %d. Bailing out.", targetHostname, sourceAgent.MountPoint.MySQLDiskUsage, targetAgent.MySQLDatadirDiskFree)) | ||
| return updateSeedStateEntry(seedStateId, fmt.Errorf("not enough disk space on target host %s, required: %d, available: %d, bailing out", targetHostname, sourceAgent.MountPoint.MySQLDiskUsage, targetAgent.MySQLDatadirDiskFree)) | ||
| } | ||
|
|
||
| // ... | ||
| seedStateId, _ = submitSeedStateEntry(seedId, fmt.Sprintf("%s will now receive data in background", targetHostname), "") | ||
| _, _ = submitSeedStateEntry(seedId, fmt.Sprintf("%s will now receive data in background", targetHostname), "") | ||
| ReceiveMySQLSeedData(targetHostname, seedId) | ||
|
|
||
| seedStateId, _ = submitSeedStateEntry(seedId, fmt.Sprintf("Waiting %d seconds for %s to start listening for incoming data", config.Config.SeedWaitSecondsBeforeSend, targetHostname), "") | ||
| _, _ = submitSeedStateEntry(seedId, fmt.Sprintf("Waiting %d seconds for %s to start listening for incoming data", config.Config.SeedWaitSecondsBeforeSend, targetHostname), "") | ||
| time.Sleep(time.Duration(config.Config.SeedWaitSecondsBeforeSend) * time.Second) | ||
|
|
||
| seedStateId, _ = submitSeedStateEntry(seedId, fmt.Sprintf("%s will now send data to %s in background", sourceHostname, targetHostname), "") | ||
|
|
@@ -762,7 +762,7 @@ func executeSeed(seedId int64, targetHostname string, sourceHostname string) err | |
| AbortSeedCommand(sourceHostname, seedId) | ||
| AbortSeedCommand(targetHostname, seedId) | ||
| Unmount(sourceHostname) | ||
| return updateSeedStateEntry(seedStateId, errors.New("10 iterations have passed without progress. Bailing out.")) | ||
| return updateSeedStateEntry(seedStateId, errors.New("10 iterations have passed without progress, bailing out")) | ||
| } | ||
|
|
||
| var copyPct int64 = 0 | ||
|
|
@@ -795,10 +795,10 @@ func executeSeed(seedId int64, targetHostname string, sourceHostname string) err | |
| return updateSeedStateEntry(seedStateId, err) | ||
| } | ||
|
|
||
| seedStateId, _ = submitSeedStateEntry(seedId, fmt.Sprintf("Submitting MySQL instance for discovery: %s", targetHostname), "") | ||
| _, _ = submitSeedStateEntry(seedId, fmt.Sprintf("Submitting MySQL instance for discovery: %s", targetHostname), "") | ||
| SeededAgents <- &targetAgent | ||
|
|
||
| seedStateId, _ = submitSeedStateEntry(seedId, "Done", "") | ||
| _, _ = submitSeedStateEntry(seedId, "Done", "") | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,7 @@ func SyncReplicaRelayLogs(instance, otherInstance *inst.Instance) (*inst.Instanc | |||||||||||||||||||||||||||||||||||||||||
| var nextCoordinates *inst.BinlogCoordinates | ||||||||||||||||||||||||||||||||||||||||||
| var content string | ||||||||||||||||||||||||||||||||||||||||||
| onResponse := func(contentBytes []byte) { | ||||||||||||||||||||||||||||||||||||||||||
| json.Unmarshal(contentBytes, &content) | ||||||||||||||||||||||||||||||||||||||||||
| _ = json.Unmarshal(contentBytes, &content) | ||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: head -n 100 go/agent/instance_topology_agent.go | tail -n 75Repository: ProxySQL/orchestrator Length of output: 2621 🏁 Script executed: sed -n '1,100p' go/agent/instance_topology_agent.goRepository: ProxySQL/orchestrator Length of output: 2655 🏁 Script executed: rg -n "func RelaylogContentsTail" --type goRepository: ProxySQL/orchestrator Length of output: 218 🏁 Script executed: rg -A 20 "func RelaylogContentsTail" --type go | head -50Repository: ProxySQL/orchestrator Length of output: 663 🏁 Script executed: rg -A 30 "func executeAgentCommand" go/agent/agent_dao.go | head -50Repository: ProxySQL/orchestrator Length of output: 1896 Don't ignore relay-log JSON decode failures. Line 33 discards Suggested fix func SyncReplicaRelayLogs(instance, otherInstance *inst.Instance) (*inst.Instance, error) {
var err error
+ var decodeErr error
var found bool
var nextCoordinates *inst.BinlogCoordinates
var content string
onResponse := func(contentBytes []byte) {
- _ = json.Unmarshal(contentBytes, &content)
+ if e := json.Unmarshal(contentBytes, &content); e != nil {
+ decodeErr = e
+ }
}
@@
if _, err := RelaylogContentsTail(otherInstance.Key.Hostname, nextCoordinates, &onResponse); err != nil {
goto Cleanup
}
+ if decodeErr != nil {
+ err = decodeErr
+ goto Cleanup
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| log.Debugf("SyncReplicaRelayLogs: stopping replication") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -72,7 +72,7 @@ Cleanup: | |||||||||||||||||||||||||||||||||||||||||
| return instance, log.Errore(err) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| // and we're done (pending deferred functions) | ||||||||||||||||||||||||||||||||||||||||||
| inst.AuditOperation("align-via-relaylogs", &instance.Key, fmt.Sprintf("aligned %+v by relaylogs from %+v", instance.Key, otherInstance.Key)) | ||||||||||||||||||||||||||||||||||||||||||
| _ = inst.AuditOperation("align-via-relaylogs", &instance.Key, fmt.Sprintf("aligned %+v by relaylogs from %+v", instance.Key, otherInstance.Key)) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return instance, err | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ProxySQL/orchestrator
Length of output: 4012
Handle JSON decode failures separately from legitimate
falsevalues.Lines 359–364 and 522–533 silently discard
json.Unmarshalerrors, causing boolean fields to default tofalsewhen responses contain malformed JSON. This pattern masks decode failures:MySQLRunningto prevent executing MySQL operations on a running instanceseedCommandCompletedreturning an accurate completion stateIf an agent endpoint returns malformed JSON with a successful HTTP status, the code treats it identically to a legitimate
falseresponse. Consider explicitly handling decode errors or separating error states from boolean results.🤖 Prompt for AI Agents