Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
How to clean up /tmp files after cloud function sends response?

I have a Google Cloud Run container acting as an express server.

End users upload files into a temporary directory, I process them, and send a file back.

I'd like to clean up the original upload (and other intermediary files) so that they don't take up memory.

But the docs say that code after the response isn't guaranteed to execute.

So how/where do I delete the temp files?

Here's a simplified example:

// process user upload, then:
res.download('someFile');
fs.unlinkSync('someFile') // not guaranteed to run;
return null;
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

With Cloud Run, you can use the CPU always ON feature. It's not the cheapest, but it specially designed to continue to work in the background, even if there isn't handled request. And that, up to 15 minutes after the latest response send and if there isn't new request on the instance.

If you use Cloud Functions 1st gen, I can recommend you to clean the /tmp dir when you start the processing of your Cloud Functions, not at the end.

Note: Cloud Functions 2nd gen is similar to Cloud Run


EDIT 1

You can play with the system and hack it to implement what you want.

After sending the response back, you can create your background process that delete the specific file in /tmp.

Because you have no longer access to CPU, that instruction will be on hold.

BUT, when the next request is received, the CPU is coming back to life for the whole instance (not for the current request) and therefore your background process will resume and delete the files.

If the instance doesn't receive a new request for the next 15 minutes, it will be offloaded, and the memory (and your files) swiped automatically!

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda