question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Endless API call with 0.16.2, strange behavior

See original GitHub issue

I just upgraded to jot 0.16.2 and I am seeing some very strange behavior.

I am using an atom to fetch the country of my users:

const currentCountryCode = atom<string>(async () => fetchCurrentCountryCode())
const defaultCountryState = atom(async (get) => get(availableCountriesState).find(({id}) => id == get(currentCountryCode)) || {id: "US", name: "United States"} )
const selectedCountryState = atomWithDefault<Country>((get) => get(defaultCountryState))

Within fetchCurrentCountryCode I am making a request to an external service:

const fetchCurrentCountryCode = async () => {
  try {
    const rawResponse = await fetch("https://extreme-ip-lookup.com/json/")
    return (await rawResponse.json()).countryCode
  }
  catch (error) {
    return null
  }
}

All of this works with jotai 0.16.1. But when i upgrade to 0.16.2 this request just hangs forever and my CPU goes crazy.

Screen Shot 2021-04-22 at 16 26 33

What is particularly weird is that it doesn’t seem an HTTP issue because I also fetch data from a backend that I host (different server, same domain). I also switched out the geolocation provider and the error stayed the same.

It also seems to have Heisenbug properties. When I add debug statements like this, it makes the request and the problem is gone.

const fetchCurrentCountryCode = async () => {
  try {
    console.log("making the API call")
    const rawResponse = await fetch("https://extreme-ip-lookup.com/json/")
    console.log("finished the api call with", rawResponse)
    return (await rawResponse.json()).countryCode
  }
  catch (error) {
    console.log("api call failed", error)
    return null
  }
}

Even worse, I can’t reproduce it on my local system.

The application is hosted on Netflify. You can see a working version with jotai 0.16.1 but I also created a deployment where the error occurs.

Click on “Create Session” to run into the infinite request (open your developer tools before you do that, after that your browser won’t react).

Reproducible in Chrome and Safari.

EDIT: There have been cases where the request worked, might try once or twice to trigger the bug.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
leifgcommented, Apr 24, 2021

The problem still persists even after removing the async keyword

0reactions
dai-shicommented, May 9, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uživatel Daishi Kato na Twitteru: „Also, I made another util ...
I just upgraded to jot 0.16.2 and I am seeing some very strange behavior. I am using an atom to fetch the country...
Read more >
Resolution of Promise atoms does not propagate correctly. #442
Endless API call with 0.16.2, strange behavior #443. Closed. fix(core): async atom infinite loop bug #444.
Read more >
REST API Call Blocking With Odd Behavior - ServiceNow
This strange behavior occurs even across browsers. For example: Open web page in Firefox and the REST table call (GET) blocks...
Read more >
@esbuild/android-arm | Yarn - Package Manager
A change that was made in version 0.15.13 accidentally introduced a case when using esbuild's JS API could cause the node process to...
Read more >
Release Notes — pandas 0.16.2 documentation - PyData |
This is a major release from 0.15.2 and includes a number of API changes, several new features, enhancements, and performance improvements along with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found