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: "Failed to retrieve real time from API, falling back to local time" #84

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

7D7-Development
Copy link

Replaced http with https inside of retrieveTimeFromApi function.

Describe Pull request
This is to fix the error: "Failed to retrieve real time from API, falling back to local time"

#83

Questions (please complete the following information):

  • Have you personally loaded this code into an updated qbcore project and checked all it's functionality? Yes.
  • Does your code fit the style guidelines? Yes.
  • Does your PR fit the contribution guidelines? Yes.

Replaced http with https inside of retrieveTimeFromApi function.
Fix: "Failed to retrieve real time from API, falling back to local time"
Copy link

@Bellck Bellck left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link

@Bellck Bellck left a comment

Choose a reason for hiding this comment

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

Reasonable fix, as API isn't loading real time, and re-loading local time.

@7D7-Development
Copy link
Author

7D7-Development commented Sep 8, 2024

After more testing, I found that the error would still occur at random, just not after every restart, as in the results before the change above.

I added to the failedCount and Wait because it seems the actual deeper issue stems from the API that is being used, as it sometimes randomly can have a longer than usual delay to load the location and time information, here is where I did further testing to get the error to go away entirely:

-- THREAD LOOPS
CreateThread(function()
    local previous = 0
    local realTimeFromApi = nil
    local failedCount = 0

    while true do
        Wait(0)
        local newBaseTime = os.time(os.date("!*t")) / 2 + 360 --Set the server time depending of OS time
        if Config.RealTimeSync then
            newBaseTime = os.time(os.date("!*t")) --Set the server time depending of OS time
            if realTimeFromApi == nil then
                retrieveTimeFromApi(function(unixTime)
                    realTimeFromApi = unixTime -- Set the server time depending on real-time retrieved from API
                end)
            end
            while realTimeFromApi == nil do
                if failedCount > 60 then --DEFAULT 10 -- TESTING HERE
                    print("Failed to retrieve real time from API, falling back to local time")
                    break
                end
                failedCount = failedCount + 1
                Wait(1000) --DEFAULT 100 -- TESTING HERE
            end
            if realTimeFromApi ~= nil then
                newBaseTime = realTimeFromApi
            end
        end
        if (newBaseTime % 60) ~= previous then --Check if a new minute is passed
            previous = newBaseTime % 60 --Only update time with plain minutes, seconds are handled in the client
            if freezeTime then
                timeOffset = timeOffset + baseTime - newBaseTime
            end
            baseTime = newBaseTime
        end
    end
end)

…time"

Added a longer wait and higher fail count.
…time"

Removed extra wait time and added more to failedCount instead.
…ack to local time"

Cleaned up notes from testing.
@ayvaniniyisi
Copy link

I have made the changes, but the Error appears after joinging game, not directly when re-starting the server, as it was before fixing.

qb weather error

@7D7-Development
Copy link
Author

Did you change http to https and also copy paste the above changes? I haven't seen this message again after making these changes, on multiple servers.

@GhzGarage GhzGarage linked an issue Nov 13, 2024 that may be closed by this pull request
@GhzGarage
Copy link
Member

So is this good to go? @7D7-Development

@GhzGarage GhzGarage self-assigned this Nov 13, 2024
@GhzGarage GhzGarage added bug Something isn't working question Further information is requested labels Nov 13, 2024
@GhzGarage GhzGarage linked an issue Nov 13, 2024 that may be closed by this pull request
@7D7-Development
Copy link
Author

7D7-Development commented Nov 14, 2024

Good to go brother. @GhzGarage

@ayvaniniyisi
Copy link

Good to go brother. @GhzGarage

I have still the error "Failed to retrieve real time from API.....etc"

Why cant this problem not be solved?

@7D7-Development
Copy link
Author

7D7-Development commented Nov 21, 2024

Good to go brother. @GhzGarage

I have still the error "Failed to retrieve real time from API.....etc"

Why cant this problem not be solved?

You must download the latest release then put in ALL of the above changes manually for this fix to work. @ayvaniniyisi
If you click "Files changed" above, you can see where you need to make the changes. This has been tested on multiple servers for well over a month now and this error is entirely gone for these servers.

@ayvaniniyisi
Copy link

You must download the latest release then put in ALL of the above changes manually for this fix to work. @ayvaniniyisi If you click "Files changed" above, you can see where you need to make the changes. This has been tested on multiple servers for well over a month now and this error is entirely gone for these servers.

But the point is that then the clock is taken from the API so that all players have the API clock and not the local time is accessed. Is that the case now?

@7D7-Development
Copy link
Author

@ayvaniniyisi The intention is to use the API to get the time of the machine that the FiveM server is running on, then sync all clients to that time instead of the usual sped up time when NOT using this option in the config.

After this PR is approved and pushed it will be fixed OR you can do the above changes as mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
4 participants