elixir-tools / elixir-tools.nvim

Neovim plugin for Elixir
MIT License
398 stars 29 forks source link

Bug: Failed to run config for elixir-tools due to GitHub rate limit #150

Closed dkarter closed 12 months ago

dkarter commented 12 months ago

Summary

Elixir Tools uses the GitHub unauthenticated API to check for new releases of the "tools" every time the editor is started and plugin is loaded. For users of ElixirLS, NextLS and Credo LSP that's 3 calls total on every start.

Whenever reaching the API rate limit of the GitHub unauthenticated API, ElixirTools fails to start.

Reproduction Steps

  1. Reach the rate limit of unauthenticated API calls (to simulate this, call the API as the plugin does, but repeat 60 times):
    repeat 60 curl --silent -i -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/elixir-tools/credo-language-server/releases/latest
  2. Open an Elixir file in Neovim, to make the plugin load

Expected

The Elixir file opens and a notification shows that the latest version of ElixirLS/CredoLS/NextLS cannot be checked due to a rate limit

Actual

ElixirTools fails to start with this error:

CleanShot 2023-07-30 at 22 37 56@2x

This breaks all LSP functionality

CleanShot 2023-07-30 at 23 21 32@2x

Cause

This error originates from this line https://github.com/elixir-tools/elixir-tools.nvim/blob/883933b57c9150c71ad2b99a4080685d83e095b8/lua/elixir/utils.lua#L55

I confirmed this was due to a rate limit being hit

CleanShot 2023-07-30 at 22 36 43@2x

And it is likely due to the assumption that curl would return an error code in this case, but it does not:

CleanShot 2023-07-30 at 23 15 35@2x

From GitHub rate limiting docs:

CleanShot 2023-07-30 at 23 00 55@2x

Suggested Solution

  1. Add --fail to the curl command in latest_release, to make it return an error code on failed attempts
  2. Adjust the notification error to mention something about rate limits https://github.com/elixir-tools/elixir-tools.nvim/blob/883933b57c9150c71ad2b99a4080685d83e095b8/lua/elixir/utils.lua#L63
CleanShot 2023-07-30 at 23 09 37@2x CleanShot 2023-07-30 at 23 10 01@2x

Alternatively, we can find a way to use the developer's GitHub auth token as part of the request, which will then increase the rate limit to 5,000 per hour which is less likely to be hit, but that seems a tad more complicated.

I'm happy to post a PR for this if my first solution sounds like a good approach.

mhanberg commented 12 months ago

Solution 1 is good for now, and yes a PR is welcome!