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 the JNI error 'global reference table overflow' caused by receiving a large number of WebSocket messages in the background #17609

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

bofeng-song
Copy link
Contributor

@bofeng-song bofeng-song commented Sep 6, 2024

Re: #
#17552

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

…ng a large number of WebSocket messages in the background
@bofeng-song bofeng-song changed the title Fix the JNI error 'global reference table overflow' caused by receivi… Fix the JNI error 'global reference table overflow' caused by receiving a large number of WebSocket messages in the background Sep 6, 2024
Copy link

github-actions bot commented Sep 6, 2024

Interface Check Report

This pull request does not change any public interfaces !

@@ -372,7 +360,7 @@ JNI_PATH(nativeOnStringMessage)(JNIEnv * /*env*/,
jlong handler) {
auto *wsOkHttp3 = HANDLE_TO_WS_OKHTTP3(handler); // NOLINT(performance-no-int-to-ptr)
std::string msgStr = JniHelper::jstring2string(msg);
RUN_IN_GAMETHREAD(wsOkHttp3->onStringMessage(msgStr));
wsOkHttp3->onStringMessage(msgStr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why change it?

The Java side has ensured that nativeOnStringMessage runs on the game thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. But i don't know why need to do synchronization in java instead in c++?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While CocosActivity run on background, the old logic will create jni's global object. And the number of global object may exeed system's limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

The current implementation also use jni to invoke java codes. Why it doesn't have the problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The global object is created during the nativeOnBinaryMessage call.

@minggo minggo merged commit 8f83193 into cocos:v3.8.5 Sep 6, 2024
24 checks passed
zhitaocai pushed a commit to zhitaocai/cocos-engine that referenced this pull request Oct 18, 2024
…ng a large number of WebSocket messages in the background (cocos#17609)
AILHC pushed a commit to AILHC/cocos-engine that referenced this pull request Oct 19, 2024
…ng a large number of WebSocket messages in the background (cocos#17609)

(cherry picked from commit 8f83193)
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.

3 participants