When utilizing Upstash with Redis operations on Vercel, the execution often gets stuck after completing

While running this code locally poses no issues, deploying it on Vercel leads to hanging. Monitoring Redis in Upstash reveals intermittent success and failure of data insertion. At times, the code smoothly passes through the await statement, but at other times, it gets stuck there.

The setup includes using Upstash's Redis with a Pay as You Go plan and Vercel with a Pro plan.

QStash by Upstash is also being utilized, facing comparable challenges where successful triggers are interchanged with instances of being stuck at the initial call. All these operations function without any glitches when executed locally.

import { Redis } from '@upstash/redis'
const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
  enableAutoPipelining: true,
  retry: {
    retries: 5,
    backoff: (retryCount) => Math.exp(retryCount) * 50,
  },
})
const result = await Promise.all([
  redis.hset(taskId + '_info', {platform,searchId,collectionId,}),
  redis.rpush(taskId, ...keywords),
  redis.expire(taskId, TASK_EXPIRY_TIME),
  redis.expire(taskId + '_info', TASK_EXPIRY_TIME)
  ]);

Various solutions have been attempted to address this issue:

  • Adjusting Vercel's function execution time: Increasing the function timeout in Vercel's settings did not eliminate the hanging problem.

  • Using Redis pipeline: Attempting to batch multiple commands together using Redis pipeline, as shown below:

const pipeline = redis.pipeline();
pipeline.hset(taskId + '_info', { /* data */ });
pipeline.rpush(taskId, ...keywords);
pipeline.expire(taskId, TASK_EXPIRY_TIME);
pipeline.expire(taskId + '_info', TASK_EXPIRY_TIME);
const results = await pipeline.exec();

However, this approach still resulted in the same hanging behavior in some cases.

  • Switching to ioredis: Trying out the ioredis library instead of Upstash's Redis client displayed similar inconsistencies in the serverless environment.

Answer №1

With auto pipelining enabled, the code examples you have shared are essentially the same.

Here are a couple of suggestions to troubleshoot:

  1. Turn off auto pipelining and execute the commands individually:
const hsetResult = await redis.hset(taskId + '_info', {platform,searchId,collectionId,})
const rpushResult = await redis.rpush(taskId, ...keywords)
const expireResult = await redis.expire(taskId, TASK_EXPIRY_TIME)
const expireResult2 = await redis.expire(taskId + '_info', TASK_EXPIRY_TIME)

This method may not be efficient due to multiple requests, but it can help in identifying any errors.

  1. Disable retry feature. If you continue to face issues, it could be related to the sdk encountering an error while attempting retries. Disabling retry might reveal the underlying problem.
const redis = new Redis({
  url: process.env.UPSTASH_REDIS_REST_URL!,
  token: process.env.UPSTASH_REDIS_REST_TOKEN!,
  enableAutoPipelining: true,
  retry: false
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What causes an error when the App is enclosed within a Provider component?

What is causing the error when wrapping the App in Provider? Are there any additional changes or additions needed? Error: "could not find react-redux context value; please ensure the component is wrapped in a @Provider@" import React from ' ...

Continuously verify if there are any active child elements

I am dealing with a recursive list of items in Angular/TypeScript. My goal is to only show items when they are either active=true; themselves or if any of their children or grandchildren are also active=true. data.json [ { "active": ...

Incorporate an external library

I am currently facing a challenge in my angular2 project where I need to import a 3rd party library. Here are the steps I have taken so far: ng new myproject npm install --save createjs-easeljs npm install @types/easeljs However, I am stuck at this poin ...

Retrieve the current state of a mat-checkbox that is dynamically generated by clicking on its associated label

Trying to transfer the state of a dynamically generated checkbox to a method triggered by clicking the label. Here's the HTML code: <div *ngFor="let label of consent.labels" style="flex-direction: column"> <div [ngClass ...

There seems to be a lack of information appearing on the table

I decided to challenge myself by creating a simple test project to dive into Angular concepts such as CRUD functions, utilizing ngFor, and understanding HttpClient methods (specifically get and post). After creating a Firebase database with an API key and ...

Mapped types: Specify mandatory properties depending on whether an array of identical objects includes a specific string value

Can an object property be set to required or optional based on the presence of a specific string in an array within the same object? type Operator = "A" | "B" type SomeStruct = { operators: Operator[]; someProp: string; // this should be ...

Error: Null is causing an issue and preventing property 'isSkipSelf' from being read in Angular7

While assembling the package for my module, I encountered the following error. TypeError: Cannot read property 'isSkipSelf' of null at ProviderElementContext._getDependency(C:\Users\ravinder\MyProjectName\node_modules\@ ...

What measures can I take to protect this API?

In the process of developing a full-stack application using Next-JS with an API connected to Firebase, my main concern revolves around ensuring the security of this API. Specifically, I am looking for ways to protect a variable called "Premium" stored in F ...

The ngOnInit lifecycle hook is not triggered by the Angular routerLink

In the component.ts file, you will find the ngOnInit function as shown below: ngOnInit() { this.locationService.getLocation().subscribe( locations => { this.locations = locations; }); } <a [routerLink]="['/locations-list&apo ...

The phrase 'tsc' is not identified as a valid cmdlet, function, script file, or executable program

Recently, I attempted to compile a TypeScript file into a JavaScript file by installing Node.js and Typescript using the command "npm install -g typescript". However, when I tried to compile the file using the command tsc app.ts, an error occurred: tsc : T ...

Mastering GraphQL querying in React using TypeScript

After successfully setting up a graphql and being able to use it in Postmen, here is how it looks: query listByName($name: String!) { listByName(name: $name) { id name sortOrder } } My variable is defined as {"name&quo ...

Why does Material-UI's "withStyles()" not function properly with a specified constructor in Typescript?

Update: Please note that there was an issue with the constructor generated by IntelliJ IDEA, but it has been fixed. You can find more details here: I'm exploring the use of Material-UI in my application, and I've encountered some challenges wit ...

Creating a custom type in Typescript using a function for testing purposes

I have been exploring ways to limit my search capabilities to specific criteria. Let's say I have a model and some data like the following: interface UserModel { _id: string; username: string; party: UserPartyModel; } interface UserParty ...

Slim specific assigned parameter

Here is some code to analyze: type T = 'a' | "b" type M = { a: 1, b: 2 } function a(a: 'a') {} function m1(a: 1) {} function f<TT extends T>(t: TT, p: M[TT]) { switch (t) { case "a": { a(t) ...

Merging Data from Multiple Forms in an Angular Application

I am currently working on my first Angular project and although I have made significant progress, I have reached a point where I feel I need assistance to complete it successfully. Project Overview: I have a class mod.ts export interface Mod { id : ...

Transitioning from MVC to Angular 2 and TypeScript: A Step-by-Step Guide

Seeking guidance as I venture into the world of Angular. My goal is to pass a string variable 'element' to my UI and utilize it. However, I am unsure about how to go about passing it inside main.js and beyond. How can I transfer a variable to a t ...

Angular model-based forms encounter an issue with converting null to an object during asynchronous validation

In my Angular app, I'm working on implementing async validation for a model-based form. I've simplified the form by removing other fields for clarity, but there are additional fields in the actual form. The goal is to check if a username is uniqu ...

What is the correct way to handle the return value of an useAsyncData function in Nuxt 3?

How can I display the retrieved 'data' from a useAsyncData function that fetches information from a pinia store? <script setup lang="ts"> import { useSale } from "~/stores/sale"; const saleStore = useSale(); const { da ...

NextJS is like the master of ceremonies in the world of backend

As I was searching for the top JS backend frameworks, I came across NextJS which is considered to be one of the best. Initially, I thought NextJS was just a simplified version of CRA and still required Node.js as the backend. This brought me back to my c ...

Issue with TypeScript Decorators: Setter function is not being invoked for an object's property

I am working on incorporating TypeScript Decorators in an Angular application to store data in local storage. This is my current goal: export function Storage() { return function (target, key): any { // property value let _val = target ...