Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SP-2353 ContributorsListControl thread safety improvements #1401

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tombogle
Copy link
Contributor

@tombogle tombogle commented Feb 25, 2025

Made ContributorsListControl more threadsafe. Possibly fixes crashes like SP-2353 or at least makes them less likely.
Added ContributorsListControl.Initialize method to allow the model to be set later when using the (existing) parameterless constructor in Designer.
Made the TestApp's ContributorsForm able to be edited in Designer and added code to test accessing various methods and properties on ContributorsListControl from a non-UI thread
Also did some minor refactoring, comment/spelling cleanup, etc.
[WIP?] See REVIEW comment at line 259 in ContributorsListControl.cs


This change is Reviewable

…w the model to be set later when using the (existing) parameterless constructor in Designer.

Made ContributorsListControl more threadsafe. Possibly fixes crashes like SP-2353 or at least makes them less likely.
Made the TestApp's ContributorsForm able to be edited in Designer and added code to test accessing various methods and properties on ContributorsListControl from a non-UI thread
Also did some minor refactoring, comment/spelling cleanup, etc.
[WIP?] See REVIEW comment at line 259 in ContributorsListControl.cs
Copy link

github-actions bot commented Feb 25, 2025

Palaso Tests

     4 files  ±0       4 suites  ±0   16m 4s ⏱️ - 2m 11s
 4 902 tests ±0   4 674 ✅ ±0  228 💤 ±0  0 ❌ ±0 
15 957 runs  ±0  15 273 ✅ ±0  684 💤 ±0  0 ❌ ±0 

Results for commit a38f0fe. ± Comparison against base commit 3813e6c.

♻️ This comment has been updated with latest results.


}

private System.ComponentModel.IContainer components = null;

Check notice

Code scanning / CodeQL

Missed 'readonly' opportunity Note

Field 'components' can be 'readonly'.

Copilot Autofix AI 3 days ago

To fix the problem, we need to add the readonly modifier to the components field. This will ensure that the field cannot be modified after the object has been initialized, preventing unintended assignments and improving code safety.

  • Locate the declaration of the components field in the ContributorsForm.Designer.cs file.
  • Add the readonly modifier to the components field declaration.
Suggested changeset 1
TestApps/SIL.Windows.Forms.TestApp/ContributorsForm.Designer.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/TestApps/SIL.Windows.Forms.TestApp/ContributorsForm.Designer.cs b/TestApps/SIL.Windows.Forms.TestApp/ContributorsForm.Designer.cs
--- a/TestApps/SIL.Windows.Forms.TestApp/ContributorsForm.Designer.cs
+++ b/TestApps/SIL.Windows.Forms.TestApp/ContributorsForm.Designer.cs
@@ -136,3 +136,3 @@
 		
-		private System.ComponentModel.IContainer components = null;
+		private readonly System.ComponentModel.IContainer components = null;
 		private System.Windows.Forms.TableLayoutPanel _tableLayout;
EOF
@@ -136,3 +136,3 @@

private System.ComponentModel.IContainer components = null;
private readonly System.ComponentModel.IContainer components = null;
private System.Windows.Forms.TableLayoutPanel _tableLayout;
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in generated code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tombogle #1402 would get rid of many such extraneous CodeQL alerts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@andrew-polk andrew-polk left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 9 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @tombogle)


SIL.Windows.Forms/ClearShare/WinFormsUI/ContributorsListControl.cs line 259 at r1 (raw file):

			{
				Logger.WriteError("Error updating contribution list", ex);
				// REVIEW: Then what? Retry every second until this succeeds???

Probably at least want something less silent?

And if we do think we will get here, probably worth documenting how/why.

…d improved error handling in HandleNewContributionListAvailable
Copy link
Contributor Author

@tombogle tombogle left a comment

Choose a reason for hiding this comment

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

Reviewable status: 7 of 9 files reviewed, 5 unresolved discussions (waiting on @andrew-polk and @Github-advanced-security[bot])


SIL.Windows.Forms/ClearShare/WinFormsUI/ContributorsListControl.cs line 259 at r1 (raw file):

Previously, andrew-polk wrote…

Probably at least want something less silent?

And if we do think we will get here, probably worth documenting how/why.

Done.


}

private System.ComponentModel.IContainer components = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in generated code.

Comment on lines +298 to +301
catch (Exception exception)
{
Logger.WriteError(exception);
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix AI about 12 hours ago

To fix the problem, we should replace the generic catch clause with specific exception types that are expected to be thrown by the code within the try block. In this case, we should catch exceptions that are likely to be thrown by Graphics.FromHwnd and LocalizationManager.GetString. These methods can throw ArgumentException, InvalidOperationException, and OutOfMemoryException. We will catch these specific exceptions and log them accordingly.

Suggested changeset 1
SIL.Windows.Forms/ClearShare/WinFormsUI/ContributorsListControl.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/SIL.Windows.Forms/ClearShare/WinFormsUI/ContributorsListControl.cs b/SIL.Windows.Forms/ClearShare/WinFormsUI/ContributorsListControl.cs
--- a/SIL.Windows.Forms/ClearShare/WinFormsUI/ContributorsListControl.cs
+++ b/SIL.Windows.Forms/ClearShare/WinFormsUI/ContributorsListControl.cs
@@ -297,3 +297,11 @@
 				}
-				catch (Exception exception)
+				catch (ArgumentException exception)
+				{
+					Logger.WriteError(exception);
+				}
+				catch (InvalidOperationException exception)
+				{
+					Logger.WriteError(exception);
+				}
+				catch (OutOfMemoryException exception)
 				{
EOF
@@ -297,3 +297,11 @@
}
catch (Exception exception)
catch (ArgumentException exception)
{
Logger.WriteError(exception);
}
catch (InvalidOperationException exception)
{
Logger.WriteError(exception);
}
catch (OutOfMemoryException exception)
{
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's okay. I don't want to make things worse if something goes wrong trying to display the error message.

Copy link
Contributor

@andrew-polk andrew-polk left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @Github-advanced-security[bot] and @tombogle)

Copy link
Contributor Author

@tombogle tombogle left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @Github-advanced-security[bot])

Comment on lines +298 to +301
catch (Exception exception)
{
Logger.WriteError(exception);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's okay. I don't want to make things worse if something goes wrong trying to display the error message.


}

private System.ComponentModel.IContainer components = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

…claimed previous implementation might cause problems, but I don't think that's true.)

Removed outdated exception comment.
Copy link
Contributor Author

@tombogle tombogle left a comment

Choose a reason for hiding this comment

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

Reviewable status: 9 of 10 files reviewed, 6 unresolved discussions (waiting on @Github-advanced-security[bot] and @tombogle)

{
return Equals(obj as Subtag);
}
public override bool Equals(object obj) => obj is Subtag subtag && Equals(subtag);

Check warning

Code scanning / CodeQL

Equals should not apply "is" Warning

Subtag.Equals(object) should not use "is" on its parameter, as it will not work properly for subclasses of Subtag.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants