Skip to content

Conversation

@zhengkunwang223
Copy link
Member

No description provided.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Jun 9, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

case <-time.After(5 * time.Second):
errorChan <- fmt.Errorf("message channel blocked")
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet has an issue where errorChan is written to after it has already been closed, which can lead to a runtime panic if any goroutines attempt to write to it afterwards. The correct approach would be to check whether errorChan is still open before writing to it.

Additionally, there's some redundancy in the use of select, since both conditions inside the select block (<-messageChan) and <-time.After() handle the same message processing logic. This could potentially make the code less readable. A more efficient way would be to have a separate channel specifically for handling timeout errors or using a timer that closes itself directly when a message is read from the other channel within its interval:

func collectLogs(params dto.StreamLog, messageChan chan<- string, errorChan chan<- error) {
    scanner := bufio.NewScanner(io.Reader)
    go func() {
        defer scanner.Close()

        timer := time.NewTimer(5 * time.Second)
        defer timer.Stop()

        for message := scanner.Text(); ; message = strings.TrimSpace(scanner.Text()), timer.Reset(5*time.Second) {
            select {
            case messageChan <- message:
                return // Exit loop on successful message transmission
            case <-errorChan:
                return // Exit loop if channel is closed (e.g., due to context cancellation)
            case <-timer.C: // Timeout reached before log message received
                errorChan <- fmt.Errorf("message channel blocked")
                return
            }
        }
    }()
}

This change ensures better resource management by closing the timer upon receiving a valid log message or encountering an immediate error condition. It also removes redundant logic within the loop.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 9, 2025

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Jun 9, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wanghe-fit2cloud

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved label Jun 9, 2025
@f2c-ci-robot f2c-ci-robot bot merged commit ed2e305 into dev-v2 Jun 9, 2025
7 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev-v2@website branch June 9, 2025 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants