Skip to content
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

fix: catch ClosedByInterruptException and handle it at debug/info #212

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.channels.Channels;
import java.nio.channels.ClosedByInterruptException;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -187,12 +188,21 @@

// Need to read more lines until we get a complete log line. Let's add this to the SB.
data.append(partialLogLine);
} catch (ClosedByInterruptException e) {
Thread.currentThread().interrupt();
logger.atInfo().log("Interrupted while reading log");
componentLogFileInformation.getLogFileInformationList().remove(0);
break;

Check warning on line 195 in src/main/java/com/aws/greengrass/logmanager/CloudWatchAttemptLogsProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/aws/greengrass/logmanager/CloudWatchAttemptLogsProcessor.java#L191-L195

Added lines #L191 - L195 were not covered by tests
} catch (IOException e) {
logger.atError().cause(e).log("Unable to read file {}", logFile.getAbsolutePath());
componentLogFileInformation.getLogFileInformationList().remove(0);
break;
}
}
} catch (ClosedByInterruptException e) {
Thread.currentThread().interrupt();
logger.atInfo().log("Interrupted while reading log");
componentLogFileInformation.getLogFileInformationList().remove(0);

Check warning on line 205 in src/main/java/com/aws/greengrass/logmanager/CloudWatchAttemptLogsProcessor.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/aws/greengrass/logmanager/CloudWatchAttemptLogsProcessor.java#L202-L205

Added lines #L202 - L205 were not covered by tests
} catch (IOException e) {
// File probably does not exist.
logger.atError().cause(e).log("Unable to read file {}", logFile.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@
* It will then get all the log files which have not yet been uploaded to the cloud. This is done by checking
* the last uploaded log file time for that component.
*/
@SuppressWarnings("PMD.CollapsibleIfStatements")
@SuppressWarnings({"PMD.CollapsibleIfStatements", "PMD.PrematureDeclaration"})
private void processLogsAndUpload() throws InterruptedException {
while (true) {
while (!Thread.currentThread().isInterrupted()) {
//TODO: this is only done for passing the current text. But in practise, we don`t need to intentionally
// sleep here.
if (!isCurrentlyUploading.compareAndSet(false, true)) {
Expand All @@ -702,6 +702,9 @@
try {
LogFileGroup logFileGroup = LogFileGroup.create(componentLogConfiguration,
lastUploadedLogFileTimeMs, workDir);
if (Thread.currentThread().isInterrupted()) {
jcosentino11 marked this conversation as resolved.
Show resolved Hide resolved
return;

Check warning on line 706 in src/main/java/com/aws/greengrass/logmanager/LogManagerService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/aws/greengrass/logmanager/LogManagerService.java#L706

Added line #L706 was not covered by tests
}

if (logFileGroup.getLogFiles().isEmpty()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.channels.ClosedByInterruptException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -89,6 +90,9 @@
} catch (FileNotFoundException e) {
// The file may be deleted as expected.
logger.atDebug().cause(e).log("The file {} does not exist", this.getAbsolutePath());
} catch (ClosedByInterruptException e) {
Thread.currentThread().interrupt();
logger.atDebug().log("Interrupted while getting log file hash");

Check warning on line 95 in src/main/java/com/aws/greengrass/logmanager/model/LogFile.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/aws/greengrass/logmanager/model/LogFile.java#L93-L95

Added lines #L93 - L95 were not covered by tests
} catch (IOException e) {
// File may not exist
logger.atError().cause(e).log("Unable to read file {}", this.getAbsolutePath());
Expand Down
Loading