Skip to content

bugfix: Resolve NullPointer and port binding errors#7397

Merged
funky-eyes merged 4 commits intoapache:2.xfrom
YongGoose:bugfix-20250531
Jun 3, 2025
Merged

bugfix: Resolve NullPointer and port binding errors#7397
funky-eyes merged 4 commits intoapache:2.xfrom
YongGoose:bugfix-20250531

Conversation

@YongGoose
Copy link
Member

@YongGoose YongGoose commented May 31, 2025

This pull request includes several updates to improve test reliability, fix bugs, and update documentation for the 2.x branch. Key changes include resolving NullPointer and port binding errors, improving test setup and teardown processes, and adding missing mock configurations.

Bug Fixes:

  • Added a new entry in the English and Chinese 2.x.md changelogs to document the resolution of NullPointer and port binding errors (#7397). [1] [2]

Test Improvements:

  • Updated ChannelEventHandlerIntegrationTest to use a different server port (8919) to avoid potential conflicts.
  • Enhanced ChannelEventListenerTest by adding a mock for ChannelId and using when to simulate channel.id() behavior. [1] [2] [3] [4] [5]
  • Improved FileSessionManagerTest by introducing @BeforeEach and @AfterEach methods to initialize and clean up SessionHolder, ensuring consistent test states. Removed redundant SessionHolder.init calls within individual tests. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Updated FileTransactionStoreManagerTest to use @BeforeEach and @AfterEach for SessionHolder setup and teardown, replacing outdated @BeforeAll and @AfterAll methods. [1] [2]

Documentation Updates:

  • Removed unnecessary blank lines in the Chinese 2.x.md changelog under the "optimize" and "refactor" sections for better formatting. [1] [2]

Signed-off-by: yongjunhong <yongjunh@apache.org>
@YongGoose YongGoose added the Do Not Merge Do not merge into develop label May 31, 2025
Signed-off-by: yongjunhong <yongjunh@apache.org>
@YongGoose
Copy link
Member Author

Error: Failures:
Error: FileSessionManagerTest.changeGlobalSessionTest:478 Expected org.apache.seata.server.console.exception.ConsoleException to be thrown, but nothing was thrown.
Error: Errors:
Error: FileSessionManagerTest.restartBranchFailRetryTest:625 » NullPointer Cannot inv...
Error: FileTransactionStoreManagerTest.init:55 » NullPointer Cannot invoke "Object.ha...
[INFO]
Error: Tests run: 170, Failures: 1, Errors: 2, Skipped: 12

@slievrly
Copy link
Member

This issue has occurred since #7363, but it seems that this PR has not updated the content associated with UT.So, this has been a potential issue, some execution environment triggers this issue?

@YongGoose
Copy link
Member Author

This issue has occurred since #7363, but it seems that this PR has not updated the content associated with UT.So, this has been a potential issue, some execution environment triggers this issue?

I’m not exactly sure which execution environment is triggering this issue.
However, similar problems have been occurring roughly once every two weeks.

The first line of defense against such potential issues would be during code review — by carefully checking for things like possible NPEs. But of course, this level of thorough review can be resource-intensive and difficult to maintain consistently.

Secondly, I think it’s important to conduct a more detailed investigation into why this kind of issue is happening intermittently. This likely requires effort and resources from the PMC and Committers to properly resolve.

Do you happen to have any ideas or suspicions about what might be causing this?

Signed-off-by: yongjunhong <yongjunh@apache.org>
Comment on lines 478 to 482
globalSession.changeGlobalStatus(GlobalStatus.CommitFailed);
SingleResult<Void> singleResult = globalSessionService.changeGlobalStatus(xid);

Assertions.assertTrue(singleResult.isSuccess());
Assertions.assertEquals(GlobalStatus.Committed, globalSession.getStatus());
Copy link
Member Author

@YongGoose YongGoose May 31, 2025

Choose a reason for hiding this comment

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

@slievrly

I’ve made some changes to the test code — would you mind taking a look and giving some feedback?

Specifically, I’m wondering whether it’s correct for changeGlobalStatus to set the status to Committed when the globalSession is initially set to CommitFailed.

When I run the tests locally, the status remains CommitFailed, but it seems status is changed to Committed in the CI environment.


A new issue has come up. 🤯

Error: Errors:
Error: FileSessionManagerTest.restartBranchFailRetryTest:629 » NullPointer Cannot inv...
Error: FileTransactionStoreManagerTest.init:55 » NullPointer Cannot invoke "Object.ha...

Copy link
Member

Choose a reason for hiding this comment

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

The failing unit tests run successfully locally, but encounter failures in the CI environment. The primary cause of failures is concurrency conflicts during test execution. After analyzing recent failed and successful CI test runs, a common factor among the failed tests is that the failing modules and the seata-namingserver module were executed in parallel. In successful CI pipelines, the execution order of seata-namingserver differs compared to failed pipelines.

Failed CI Test Runs:

Building seata-namingserver 2.5.0-SNAPSHOT 2.5.0-SNAPSHOT [46/95]

https://productionresultssa19.blob.core.windows.net/actions-results/83180f59-5dd1-4580-8fab-ecbd533fc7db/workflow-job-run-a61cbcdc-67ab-53c0-e38e-eb145948c9c8/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-06-02T14%3A28%3A09Z&sig=XV8KixW%2BzJw%2FAq3iVJE0gZ5mi%2Be844H185q%2F9n45nj0%3D&ske=2025-06-03T02%3A05%3A08Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-06-02T14%3A05%3A08Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-06-02T14%3A18%3A04Z&sv=2025-05-05

https://productionresultssa8.blob.core.windows.net/actions-results/42d9725b-eeaf-4b7f-bcbb-aa1326e04c30/workflow-job-run-a61cbcdc-67ab-53c0-e38e-eb145948c9c8/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-06-02T14%3A27%3A29Z&sig=%2BmRaZp4PdTs3y2f5ASIqWs8S%2F9i%2BRhqjP4X8zI%2BA2Vc%3D&ske=2025-06-03T02%3A11%3A30Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-06-02T14%3A11%3A30Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-06-02T14%3A17%3A24Z&sv=2025-05-05

https://productionresultssa10.blob.core.windows.net/actions-results/20924427-f5e2-4d8c-b56a-b7d9fb10883e/workflow-job-run-a61cbcdc-67ab-53c0-e38e-eb145948c9c8/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-06-02T14%3A26%3A25Z&sig=qqpeIUAPM8vvwM7aXE51WtRAzg8qAELvcExM2AX%2ByDc%3D&ske=2025-06-03T02%3A11%3A46Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-06-02T14%3A11%3A46Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-06-02T14%3A16%3A20Z&sv=2025-05-05


Successful CI Test Runs:

Building seata-namingserver 2.5.0-SNAPSHOT 2.5.0-SNAPSHOT [80/95]

https://productionresultssa4.blob.core.windows.net/actions-results/b9f7981b-dfb8-4455-bc2c-4818172d2177/workflow-job-run-a61cbcdc-67ab-53c0-e38e-eb145948c9c8/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-06-02T14%3A25%3A45Z&sig=VFvYuzl%2BlJtBLjQnm92wbi8ulOcxzIS%2FOptsHVckjWs%3D&ske=2025-06-03T02%3A05%3A12Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-06-02T14%3A05%3A12Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-06-02T14%3A15%3A40Z&sv=2025-05-05

https://productionresultssa18.blob.core.windows.net/actions-results/a550f61a-b8f9-4bb1-ba7a-ecaf0de03ea8/workflow-job-run-a61cbcdc-67ab-53c0-e38e-eb145948c9c8/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-06-02T14%3A22%3A21Z&sig=C3y1GMxnCrjfN2aCKT4XEF6A7ih6qdWrFQ7zwqoRNz4%3D&ske=2025-06-03T02%3A11%3A36Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-06-02T14%3A11%3A36Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-06-02T14%3A12%3A16Z&sv=2025-05-05

https://productionresultssa8.blob.core.windows.net/actions-results/2828a27a-15ce-4679-9aa0-4746f6d785e2/workflow-job-run-a61cbcdc-67ab-53c0-e38e-eb145948c9c8/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-06-02T14%3A24%3A55Z&sig=JyhVNNIjM1eBEBalIYmB7A%2BnEDe2iaJvAu9GfVfrexo%3D&ske=2025-06-03T02%3A05%3A17Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-06-02T14%3A05%3A17Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-06-02T14%3A14%3A50Z&sv=2025-05-05

Copy link
Member

Choose a reason for hiding this comment

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

This issue is currently blocking the release of version 2.4.0. As a short-term mitigation, we can temporarily resolve it by controlling the execution order of unit tests to avoid concurrency conflicts. In the long term, we need to implement robust support for concurrent multi-module testing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tomorrow is a public holiday in South Korea, so I’ll make sure to finish the work by then.
I’ll also try reordering the unit tests as you suggested.

Copy link
Member Author

Choose a reason for hiding this comment

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

This issue is currently blocking the release of version 2.4.0. As a short-term mitigation, we can temporarily resolve it by controlling the execution order of unit tests to avoid concurrency conflicts. In the long term, we need to implement robust support for concurrent multi-module testing.

@slievrly @funky-eyes

Would it be better to create a separate issue for this?
If you have any suggestions or ideas on how to approach it, I’d really appreciate your comments!

@OmCheeLin
Copy link
Contributor

Should we have the system randomly allocate a free port instead of manually specifying it for port binding issues?

@OmCheeLin
Copy link
Contributor

OmCheeLin commented Jun 2, 2025

I noticed that Seata encountered an error while attempting to restore a BranchSession from a file — the transactionId was 0, which is invalid and caused the restore to fail.
This is likely due to concurrent writes, shared session files, or incomplete cleanup.
It works fine in our local environment, but fails in the CI pipeline.
in FileSessionManagerTest.java

@funky-eyes
Copy link
Contributor

I think the issue is caused by changes in the CI running environment. Perhaps we should specify a stable Linux environment and JDK version (rather than using the latest version).

@YongGoose
Copy link
Member Author

I think the issue is caused by changes in the CI running environment. Perhaps we should specify a stable Linux environment and JDK version (rather than using the latest version).

Feel free to update my PR to test that case — the Allow edits and access to secrets by maintainers setting is enabled.

@YongGoose
Copy link
Member Author

@slievrly

I’m unable to access the link you shared — it shows an AuthenticationFailed error.
Is there another way I can check how the order was changed?

Signed-off-by: yongjunhong <yongjunh@apache.org>
@codecov
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.77%. Comparing base (73de87c) to head (26ca42b).
Report is 4 commits behind head on 2.x.

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #7397      +/-   ##
============================================
+ Coverage     58.44%   58.77%   +0.32%     
  Complexity      535      535              
============================================
  Files          1272     1272              
  Lines         45862    45862              
  Branches       5522     5522              
============================================
+ Hits          26806    26957     +151     
+ Misses        16532    16351     -181     
- Partials       2524     2554      +30     

see 54 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@YongGoose
Copy link
Member Author

YongGoose commented Jun 3, 2025

This change has increased the CI execution time by about one minute.
I believe this should be considered a temporary measure and must be addressed properly in the near future.

image

@YongGoose YongGoose removed the Do Not Merge Do not merge into develop label Jun 3, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses NullPointerException and port binding errors, improves test setup/teardown to avoid conflicts, and updates changelogs for the 2.x branch.

  • Added changelog entries in English and Chinese for bug #7397.
  • Switched server port in an integration test and enhanced unit tests with proper lifecycle hooks.
  • Replaced static @BeforeAll/@AfterAll with @BeforeEach/@AfterEach in session store tests and added mocks in channel listener tests.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/src/test/java/.../FileTransactionStoreManagerTest.java Swapped @BeforeAll/@AfterAll for per-test setup/teardown.
server/src/test/java/.../FileSessionManagerTest.java Replaced class-level hooks with @BeforeEach/@AfterEach, removed redundant SessionHolder.init calls, and simplified a test.
core/src/test/java/.../ChannelEventListenerTest.java Added ChannelId mock and when(channel.id()) stubbing.
core/src/test/java/.../ChannelEventHandlerIntegrationTest.java Updated the hardcoded server port from 8091 to 8919.
changes/zh-cn/2.x.md Inserted bugfix entry and adjusted spacing in the Chinese changelog.
changes/en-us/2.x.md Inserted bugfix entry in the English changelog.
Comments suppressed due to low confidence (1)

server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java:472

  • This TODO indicates missing test coverage for global session failure status transitions; consider adding tests to verify FAIL_COMMIT and FAIL_ROLLBACK states as noted.
// TODO: After implementing robust support for concurrent multi-module tests, add tests to verify that globalSession transitions to FAIL_COMMIT_STATUS and FAIL_ROLLBACK_STATUS.

Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

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

LGTM

@funky-eyes funky-eyes merged commit d845d45 into apache:2.x Jun 3, 2025
13 checks passed
@slievrly
Copy link
Member

slievrly commented Jun 3, 2025

@slievrly

I’m unable to access the link you shared — it shows an AuthenticationFailed error. Is there another way I can check how the order was changed?

The current order is still in the wrong order, but it looks like the resource cleanup in PR has solved the problem.

You can follow these steps to check:

  1. Click on the commit status of the merged PR, select a CI environment. For example, choose the build / build (8) (push) environment and click Detail.

image

  1. Click the Settings button in the top-right corner, select View raw logs, and review the detailed logs in the new page.
    Use the browser's search function (Ctrl+F/Cmd+F) to find the execution order of each module.

image

@slievrly slievrly added this to the 2.5.0 milestone Jun 3, 2025
@YongGoose
Copy link
Member Author

The current order is still in the wrong order, but it looks like the resource cleanup in PR has solved the problem.

Thank you so much for your detailed response! 👍🏻

The change is only a temporary, so we’ll need to take further steps to ensure long-term test stability.
I’ve sent you an email regarding this — would you mind taking a look when you get a time?

Thanks again!

jsbxyyx pushed a commit to jsbxyyx/incubator-seata that referenced this pull request Jun 11, 2025
jsbxyyx pushed a commit to jsbxyyx/incubator-seata that referenced this pull request Jun 11, 2025
slievrly pushed a commit to slievrly/fescar that referenced this pull request Oct 21, 2025
YvCeung pushed a commit to YvCeung/incubator-seata that referenced this pull request Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants