ho-dev / HattrickOrganizer

Assistant for Hattrick online football manager
https://ho-dev.github.io/HattrickOrganizer/
GNU Lesser General Public License v3.0
195 stars 79 forks source link

[BUG] OAuth Access token not preserved on macos #811

Closed tychobrailleur closed 3 years ago

tychobrailleur commented 3 years ago

Describe the bug When restarting HO on Macos, some users are prompted with the OAuth challenge, which indicates that the OAuth access token doesn't seem to be stored in the USERCONFIGURATION table.

To Reproduce Steps to reproduce the behavior:

  1. Start HO
  2. Download details from Hattrick, connect using OAuth
  3. Shut down HO
  4. Start HO again
  5. Try downloading details again from Hattrick: OAuth challenge is prompted again.

Screenshots N/A

Platform information:

Additional context N/A

tychobrailleur commented 3 years ago
Screenshot 2020-11-29 at 14 27 52
tychobrailleur commented 3 years ago

That is quite a strange one – I thought that using the closing button in the titlebar was solving the problem, but it seems to be happening randomly, as if there was some sort of race condition between windowClosed and windowClosing?

dtslvr commented 3 years ago

I don't know if it's related, but besides adding the access token every time I also have to set the path of my .hrf files.

akasolace commented 3 years ago

@tychobrailleur have you had time to look at this one ?

tychobrailleur commented 3 years ago

I don't know if it's related, but besides adding the access token every time I also have to set the path of my .hrf files.

Thanks @dtslvr, it is related: user preferences (incl. OAuth access token) don't get saved when HO exits. Arguably we could save it right after we have retrieved from HT.

@tychobrailleur have you had time to look at this one ?

I haven't, but I am looking at it right now, hopefully I should have a fix soon. As an aside, I am experiencing an NPE with master due Youth changes:

java.lang.NullPointerException
    at core.file.xml.ConvertXml2Hrf.createHrf(ConvertXml2Hrf.java:148)
    at core.net.OnlineWorker.getHrf(OnlineWorker.java:80)
    at core.net.DownloadDialog.startDownload(DownloadDialog.java:271)
    at core.net.DownloadDialog.actionPerformed(DownloadDialog.java:92)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)

and line 148 in ConvertXml2Hrf:

        int youthteamId = HOVerwaltung.instance().getModel().getBasics().getYouthTeamId();
tychobrailleur commented 3 years ago

That is quite a strange one – I thought that using the closing button in the titlebar was solving the problem, but it seems to be happening randomly, as if there was some sort of race condition between windowClosed and windowClosing?

I am convinced there is a race condition here, as this takes the form of a “heisenbug”: when adding logging statements to debug (or simply debugging), the problem disappears... What is unclear to me is whether something changed in HO or the JDK to cause this issue to emerge. Or if the problem was always there but somehow now appears due some changes.

tychobrailleur commented 3 years ago

I have created a PR with a fix that seems to work locally. Having not been able to track down the cause of this, I am not fully convinced this fixes the issue for good, it would be great to have other people try out this fix (this may be challenging due to some NPEs on master).

wsbrenk commented 3 years ago

@tychobrailleur great to see you back. Concerning youth NPE. Thanks for that. Will fix this immediately. I guess you don't have an academy, which is a big mistake;-)

More concerning this, in my "youth-ticket" #367

cmeury commented 3 years ago

I still have this problem; version 4.1.3310.2 on MacOS 11.5. Also, preferences do not seem to get saved either. Should I open a new issue for this?

wsbrenk commented 3 years ago

@cmeury this fix is not part of the 4.1 release version. You could test if it is fixed with a new 5.0-DEV-version. But at your own risc. Please don't do it without backups of your database and program folders.

cmeury commented 3 years ago

Thanks @wsbrenk -- it seems to be resolved with 5.0.3730.0. I can close and re-open HO and it will not ask me for the token anymore.