UNIT3D-Community-Edition icon indicating copy to clipboard operation
UNIT3D-Community-Edition copied to clipboard

[Bug] Serialization of 'Closure' is not allowed

Open LostRager opened this issue 1 year ago • 17 comments

UNIT3D Version

8.1.3

PHP & Platform

8.3.7

Laravel verion

11.5.0

Have you done this?

  • [X] I am willing to share my stack trace and logs
  • [ ] I can suggest a fix as a Pull Request

Expectation

Serialization of 'Closure' is not allowed

Description

Serialization of 'Closure' is not allowed

Stack trace & logs

Serialization of 'Closure' is not allowed {"userId":3572,"exception":"[object] (Exception(code: 0): Serialization of 'Closure' is not allowed at /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php:406)
[stacktrace]
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(406): serialize()
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(108): Illuminate\\Cache\\RedisStore->serialize()
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(225): Illuminate\\Cache\\RedisStore->put()
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(407): Illuminate\\Cache\\Repository->put()
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(440): Illuminate\\Cache\\Repository->remember()
#5 /var/www/html/app/Http/Controllers/API/TorrentController.php(525): Illuminate\\Cache\\CacheManager->__call()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\\Http\\Controllers\\API\\TorrentController->filter()
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Illuminate\\Routing\\Controller->callAction()
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(206): Illuminate\\Routing\\Route->runController()
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#12 /var/www/html/app/Http/Middleware/CheckIfBanned.php(45): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\CheckIfBanned->handle()
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequestsWithRedis.php(65): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(127): Illuminate\\Routing\\Middleware\\ThrottleRequestsWithRedis->handleRequest()
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(89): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequestUsingNamedLimiter()
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(64): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Auth\\Middleware\\Authenticate->handle()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(805): Illuminate\\Pipeline\\Pipeline->then()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack()
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(748): Illuminate\\Routing\\Router->runRoute()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute()
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch()
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#27 /var/www/html/vendor/livewire/livewire/src/Features/SupportDisablingBackButtonCache/DisableBackButtonCacheMiddleware.php(19): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Livewire\\Features\\SupportDisablingBackButtonCache\\DisableBackButtonCacheMiddleware->handle()
#29 /var/www/html/app/Http/Middleware/BlockIpAddress.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#30 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): App\\Http\\Middleware\\BlockIpAddress->handle()
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(62): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#32 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle()
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#41 /var/www/html/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#42 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\ValidatePostSize->handle()
#43 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#44 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#45 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then()
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#48 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1168): Illuminate\\Foundation\\Http\\Kernel->handle()
#49 /var/www/html/public/index.php(17): Illuminate\\Foundation\\Application->handleRequest()
#50 {main}
"}

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

LostRager avatar May 22 '24 05:05 LostRager

Do you know what http request triggered this? How frequently do you get this error?

Roardom avatar May 22 '24 06:05 Roardom

Do you know what http request triggered this? How frequently do you get this error?

I just noticed its the same userid everytime. Its every 10 minutes. I tried looking at the access logs, but i dont see anything jumping out at me.

Here is 1ms before, at and 1ms after the error is logged:

xx.xx.xx - - [22/May/2024:09:02:09 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&free[]=100&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 5944158 "-" "Prowlarr/1.15.0.4361 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:09 +0200] "GET /api/torrents/filter?name=i+feel+bad+S01&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 344 "-" "Prowlarr/1.17.1.4483 (ubuntu 24.04)"
xx.xx.xx - - [22/May/2024:09:02:09 +0200] "GET /api/torrents/filter?name=Skee+Mask+-+ISS007+-+2022&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 344 "-" "Prowlarr/1.17.2.4511 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:09 +0200] "GET /api/torrents/filter?categories[]=3&categories[]=10&name=Kendrick+Lamar+She+Needs+Me+remix+ringtone&free[]=100&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 344 "-" "Prowlarr/1.17.2.4511 (windows 10.0.22631.0)"
xx.xx.xx - - [22/May/2024:09:02:09 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1473013 "-" "Prowlarr/1.11.4.4173 (alpine 3.18.5)"
xx.xx.xx - - [22/May/2024:09:02:09 +0200] "GET /api/torrents/filter?name=Star+Wars+-+The+Clone+Wars+2008+S03E05&seasonNumber=3&episodeNumber=5&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 344 "-" "Prowlarr/1.18.0.4513 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&name=S02&seasonNumber=2&tvdbId=309523&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 344 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1472895 "-" "Prowlarr/1.17.2.4511 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1471700 "-" "Prowlarr/1.17.2.4511 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?name=Power+Rangers+S17&seasonNumber=17&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 344 "-" "Prowlarr/1.17.2.4511 (arch 1.0)"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?sortField=seeders&sortDirection=desc&perPage=100 HTTP/1.1" 500 1650 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?name=The+Last+Samurai+2003&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 65096 "-" "Prowlarr/1.16.2.4435 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&name=SpongeBob+Schwammkopf+S13E23&seasonNumber=13&episodeNumber=23&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 344 "-" "Prowlarr/1.17.1.4483 (ubuntu 24.04)"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1576531 "-" "Prowlarr/1.17.2.4511 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?categories[]=3&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1696104 "-" "Prowlarr/1.17.2.4511 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:11 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1471739 "-" "Prowlarr/1.17.2.4511 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:11 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1471753 "-" "Prowlarr/1.16.2.4435 (alpine 3.19.1)"
xx.xx.xx - - [22/May/2024:09:02:11 +0200] "GET /api/torrents/filter?categories[]=2&categories[]=6&sortField=created_at&sortDirection=desc&perPage=100 HTTP/1.1" 200 1471739 "-" "Prowlarr/1.17.2.4511 (alpine 3.19.1)"```

LostRager avatar May 22 '24 07:05 LostRager

I assume its this one since its error 500: xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?sortField=seeders&sortDirection=desc&perPage=100 HTTP/1.1" 500 1650 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"

LostRager avatar May 22 '24 07:05 LostRager

I assume its this one since its error 500: xx.xx.xx - - [22/May/2024:09:02:10 +0200] "GET /api/torrents/filter?sortField=seeders&sortDirection=desc&perPage=100 HTTP/1.1" 500 1650 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"

Yup, tested it with prowlarr. It does not like beeing sorted by seeders or size; title and created_at works fine.

LostRager avatar May 22 '24 07:05 LostRager

Amazing, thanks. Is one of the torrents with the most seeds lacking a type?

Roardom avatar May 22 '24 07:05 Roardom

I should clarify that I can't easily reproduce this. My best guess is that one of the torrents in the results is throwing errors inside here: https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/master/app/Http/Resources/TorrentResource.php and it's trying to cache the closure generated by the error.

Roardom avatar May 22 '24 07:05 Roardom

Amazing, thanks. Is one of the torrents with the most seeds lacking a type?

There are game_meta and no_meta torrents in the top seeded. Maybe its something related to resolution/poster/genres? Usually where the issues are.

For the size sorting, there are 3 no_meta torrents and 1 game.

LostRager avatar May 22 '24 08:05 LostRager

Tested it, seems like there is an issue with games. postponed the no_meta torrents and it still got the error. Postponed the game torrent and the issue went away.

~~My guess is genres since games uses array for genres.~~ Tested this by setting genres to empty string, no change.

LostRager avatar May 22 '24 08:05 LostRager

Tested it, seems like there is an issue with games. postponed the no_meta torrents and it still got the error. Postponed the game torrent and the issue went away.

~My guess is genres since games uses array for genres.~ Tested this by setting genres to empty string, no change.

Hmm my guess is https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/68ef67e0fd44e430c1130ef7520c4a7479c0ba53/app/Http/Resources/TorrentResource.php#L32 causing issues with games. I'll look into it. It doesnt account for games.

HDVinnie avatar May 22 '24 11:05 HDVinnie

@LostRager Any luck figuring out which array key in the json response is triggering the 500?

Roardom avatar Jun 14 '24 00:06 Roardom

@LostRager Any luck figuring out which array key in the json response is triggering the 500?

No, i have not figured it out since last time we talked. Its definitly something to do with games tho. I tried setting most of the torrentresources to '' but no change. I also tried to just remove the whole meta attribute, but no change.

Not quite sure how to test further.

LostRager avatar Jun 14 '24 18:06 LostRager

Did some more testing, if i comment out $this->scopeMeta($torrents); there is no more error, same if i remove all game stuff from the scopeMeta function.

Any ideas what could be causing issues for just games in this case?

LostRager avatar Jul 12 '24 17:07 LostRager

scopeMeta is found here: https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/master/app/Traits/TorrentMeta.php. It simply sets the meta for each torrent in the collection using eager loading for movies/tv. Maybe isset($this->meta->poster) in TorrentResource needs to be changed to isset($this->meta['poster']) (same for genres)? Does removing the meta entry from the TorrentResource fix it too?

I only just thought of this, but you could try removing the cache on the api torrent controller and query it directly that way you can generate the proper error and proceed from there.

Roardom avatar Jul 13 '24 00:07 Roardom

scopeMeta is found here: https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/master/app/Traits/TorrentMeta.php. It simply sets the meta for each torrent in the collection using eager loading for movies/tv. Maybe isset($this->meta->poster) in TorrentResource needs to be changed to isset($this->meta['poster']) (same for genres)? Does removing the meta entry from the TorrentResource fix it too?

I only just thought of this, but you could try removing the cache on the api torrent controller and query it directly that way you can generate the proper error and proceed from there.

No, doing anything in the TorrentResource does nothing as far as i can see.

Removing the cache from the code fixes the issue, and all the info are correct, there are no missing values and it even has genres.

LostRager avatar Jul 13 '24 00:07 LostRager

With the cache code turned off:

"data": [
        {
            "type": "torrent",
            "id": "32520",
            "attributes": {
                "meta": {
                    "poster": "https://via.placeholder.com/90x135",
                    "genres": "XXX, XXXX"
                },
                "name": "XXXXXXXXXXXXXXXX",
                "release_year": null,
                "category": "Game",
                "type": "Windows",
                "media_info": null,
                "bd_info": null,
                "description": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                "info_hash": "169a247a9b5901de9332cdd4dd1d8bb1c0ab70dd",
                "size": 233988886457,
                "num_file": 2,
                "files": [
                    {
                        "index": 1,
                        "name": "XXX.iso",
                        "size": 233988882432
                    },
                    {
                        "index": 2,
                        "name": "XXX.nfo",
                        "size": 4025
                    }
                ],
                "freeleech": "100%",
                "double_upload": false,
                "refundable": false,
                "internal": 0,
                "featured": false,
                "personal_release": 0,
                "uploader": "XXX",
                "seeders": 0,
                "leechers": 0,
                "times_completed": 3,
                "tmdb_id": 0,
                "imdb_id": 0,
                "tvdb_id": 0,
                "mal_id": 0,
                "igdb_id": 204985,
                "category_id": 4,
                "type_id": 13,
                "created_at": "2023-08-17T01:36:05.000000Z",
                "download_link": "https://XXX/torrent/download/32520.XXXX",
                "details_link": "https://XXX/torrents/32520"
            }
        },

LostRager avatar Jul 13 '24 01:07 LostRager

Could it be something like it takes to long fetch the game meta so it tries to cache before the meta is set? Getting game meta usually takes quite a while and should probably be saved to the database instead of collected every time you try to fetch a game.

LostRager avatar Jul 13 '24 01:07 LostRager

Strange... I would have expected a 500 error with the cache removed.

I think the default time out is 30 seconds if I recall correctly, but I would have expected a proper error if that would have happened. If the closure successfully completes without an exception, then the response should be correctly received, but the closure is throwing an exception which from what I understand is causing this error.

It would indeed be nice to store this data directly in the database. Only the movie and tv tables have been moved into the database so far.

Roardom avatar Jul 13 '24 01:07 Roardom

This issue seems to be fixed in the 8.2.0 update, or it fixed itself when i rebased.

LostRager avatar Sep 20 '24 20:09 LostRager