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

System.UserInfo.getSessionId() throws System.UnexpectedException #761

Open
krishnandusarkarprax opened this issue Sep 4, 2024 · 1 comment
Labels
Layer: Logger Engine Items related to the core logging engine Type: Bug Something isn't working

Comments

@krishnandusarkarprax
Copy link

Package Edition of Nebula Logger

Unlocked Package

Package Version of Nebula Logger

4.13.17

New Bug Summary

Package Edition of Nebula Logger
Unlocked Package

Package Version of Nebula Logger
4.13.17

New Bug Summary
When a user logs in through a server-to-server connected app with the setting "Issue JSON Web Token (JWT)-based access tokens for named users" enabled tries to use a Logger.xxx method, a Salesforce System Error is thrown.

Debugging reveals that the issue occurs when System.UserInfo.getSessionId() is called. Even with a try/catch block around this call, the code doesn't reach the catch block; instead, the error is thrown directly.

The only workaround is to disable the "Issue JSON Web Token (JWT)-based access tokens for named users" setting.

Defect #598 was reported a few months ago, leading to the resolution of adding a try/catch block around this code. However, despite the latest Salesforce Release (Winter '25) and Nebula Logger (version 4.13.17), the issue persists.

Screenshot 2024-09-04 at 10 30 33 PM Screenshot 2024-09-04 at 10 31 05 PM
@krishnandusarkarprax krishnandusarkarprax added the Type: Bug Something isn't working label Sep 4, 2024
@jongpie
Copy link
Owner

jongpie commented Sep 12, 2024

@krishnandusarkarprax thanks for reporting this! Trying to get the user's session has been such a headache for years (issues #97 is another example where this came up ~3 years ago), and I haven't run into this particular issue myself before, so I appreciate the info & context.

Is it feasible for you to add this code snippet somewhere in your org (either in the Logger class somewhere, or one of your own Apex classes)? It just needs to be added in some Apex method that would be called in your scenario when you're using the setting "Issue JSON Web Token (JWT)-based access tokens for named users"

Integer currentSessionCount = [
    SELECT COUNT() FROM AuthSession
    WHERE UsersId = :System.UserInfo.getUserId() AND IsCurrent = TRUE
];
System.debug('Count of current sessions for the current user: ' + currentSessionCount);

If you're able to add that & run it, let me know what output you see. I'm wondering if the count will be 0 or 1 in this situation. If it ends up being 0, then I might be able to run that query first, and not call System.UserInfo.getSessionId() to avoid the uncatchable System.UnexpectedException error.

@jongpie jongpie added the Layer: Logger Engine Items related to the core logging engine label Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Layer: Logger Engine Items related to the core logging engine Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants