laravel-idempotency
laravel-idempotency copied to clipboard
Serialization of Closure Not Allowed
After upgrading to Laravel 5.7, I'm getting a Serialization of Closure not allowed on a ton of my requests. The error went away when I disabled this middleware. Help!
More details, it only seems to occur in my Redis Store. Here's a full stack trace: https://sentry.io/share/issue/9b7f938e4bb6410f9ae6d5c2bbddae46/
Following the issue, did you resolve the issue? I've tried it on Laravel 5.7 and Laravel 5.8 with no problems. Seems like you have something attached to the response object that cannot be serialized.
@javidalpe I haven't been able to resolve this yet because it's a really intermittent issue that occurs in the production environment with a decent volume of requests, so I haven't been able to reproduce it and I can't leave the prod env broken. I'm not sure of the best way to go about debugging it yet.
$response = $next($request);
$response->header(self::IDEMPOTENCY_HEADER, $requestId);
Cache::put($requestId, $response, self::EXPIRATION_IN_MINUTES);
In my case I have found that if $response is of type Illuminate\Http\Response, Cache is able to serialise and save it. However if $response is of type Illuminate\Http\JsonResponse I get the Serialization of closure is not allowed error message.
I don't any work around for it. any suggestions?
For any one still having the issue, this works fine for me
Cache::put($requestId, [
"response" => $response->getContent(),
"path" => $request->path(),
"status" => $response->status()
], now()->addMinutes(self::EXPIRATION_IN_MINUTES));
