adamint / spotify-web-api-kotlin

Spotify Web API wrapper for Kotlin, Java, JS, and Native - Targets JVM, Android, JS (browser), Native (Desktop), and Apple tvOS/iOS. Includes a Spotify Web Playback SDK wrapper for Kotlin/JS, and a spotify-auth wrapper for Kotlin/Android.
https://adamint.github.io/spotify-web-api-kotlin-docs/
MIT License
194 stars 21 forks source link

getAlbumTracks 400 Error when called often #310

Closed michaeldomanek closed 1 year ago

michaeldomanek commented 2 years ago

Describe the bug when I call api.albums.getAlbumTracks() for a lot of albums (e.g. 40 or 80), I get Received Status Code 400. Error cause: malformed request sent for some requests

To Reproduce

val api = spotifyAppApi()
val tracks = albumIds.flatMap { albumId ->
    api.albums.getAlbumTracks(albumId).getAllItemsNotNull()
}

create albumIds list from this file: albumIds.txt

Desktop:

adamint commented 2 years ago

Does this occur for the same ids every time?

michaeldomanek commented 2 years ago

no every time other ids and sometimes it doesn't happen and sometimes e.g 5 request fail (avg. 2-6 requests fail)

adamint commented 2 years ago

I have not reproduced this bug.

adamint commented 2 years ago

Apologies, that was a typo. I have not been able to reproduce this bug on kotlin 1.6.20, version 3.8.6 @michaeldomanek after several thousands of requests. My code:

suspend fun main() = runBlocking {
    val api = spotifyAppApi("", "").build()
    api.spotifyApiOptions.enableDebugMode = true
    api.spotifyApiOptions.useCache = false

    val albumIds = File("${System.getProperty("user.home")}/Downloads/albumIds.txt").readText()
        .replace("[\\[\\]]".toRegex(), "")
        .split(", ")

    while (true) {
        val tracks = albumIds.map { albumId ->
            async {
                api.albums.getAlbumTracks(albumId).getAllItemsNotNull()
            }
        }.awaitAll()

        println(tracks)
    }

}

Can you give me more information around this behavior? Is there a particular exception or stacktrace you can share

michaeldomanek commented 2 years ago

Hello @adamint thanks for looking into it. This is my Stacktrace: Stacktrace.txt I edited my comment because yesterday I thought it was a Java 17 problem and changing sdk solved the problem, but today it happened with other Java versions too.

michaeldomanek commented 2 years ago

I created a new sample project to test it: kotlin-gradle-example The Stacktrace is from here if you want to look at it.

adamint commented 2 years ago

Hi @michaeldomanek, I'm still unable to reproduce this with the given sample, on various JDKs (8, 11, 17). You reproduced it in this sample project? Do you have the debug console logs listing the request (from enableDebugMode)

adamint commented 1 year ago

No additional info was provided, closing