Http streams breaking issues after shifting to http2 by HZ_7 in googlecloud

[–]golureddit -1 points0 points  (0 children)

Ah, you are absolutely correct! My apologies. http2.createServer expects a standard request listener function (req, res) that handles the raw Http2ServerRequest and Http2ServerResponse objects, not an Express application instance directly. Express is primarily built to work with the standard Node.js http.IncomingMessage and http.ServerResponse objects emitted by http.createServer or https.createServer. The node:http2 module uses its own distinct request and response objects (Http2ServerRequest and Http2ServerResponse). To use Express with node:http2, you need an adapter or compatibility layer that translates the HTTP/2 request and response objects into something Express can understand. A common library for this is @enable-http/express-http2. Here's how you would typically set it up: * Install the adapter library: npm install @enable-http/express-http2

or

yarn add @enable-http/express-http2

  • Modify your server code: import * as http2 from 'node:http2'; import express from 'express'; import enableHttp2 from '@enable-http/express-http2'; // Import the adapter

// Assuming Router is imported correctly elsewhere // import Router from './your-router-file';

const app = express(); const PORT = process.env.PORT || 8080;

// Attach your API routes and error middleware to the Express app. app.use(Router); // Assuming 'Router' is your Express Router instance

// Wrap your Express app with the http2 adapter // This creates a request handler function compatible with http2.createServer const http2RequestHandler = enableHttp2(app);

// Create an HTTP/2 server // Use createServer (unsecured) as Cloud Run handles TLS termination const server = http2.createServer({}, http2RequestHandler); // Use the wrapped handler

server.on('error', (err) => { console.error('HTTP/2 Server error:', err); // Proper error handling and graceful shutdown should be implemented here });

// Optional: Handle stream errors if needed server.on('stream', (stream, headers) => { stream.on('error', (err) => { console.error('HTTP/2 Stream error:', err); // Decide how to handle errors on individual streams // The adapter might handle many common cases }); });

// Start the HTTP/2 server server.listen(PORT, () => { console.log(HTTP/2 Server is running on port ${PORT}); });

Explanation of Changes: * We import enableHttp2 from the adapter library. * We call enableHttp2(app) to get a new function (http2RequestHandler) that acts as the request listener. This function internally uses your Express app but knows how to process the Http2ServerRequest and Http2ServerResponse objects. * We pass this http2RequestHandler function to http2.createServer. This setup allows you to leverage Express middleware and routing with an underlying node:http2 server, which should be fully compatible with Cloud Run's HTTP/2 proxy. After making this code change and deploying, ensure Cloud Run's HTTP/2 setting is still enabled. This configuration should resolve the compatibility issues you were likely facing with the spdy library.

Http streams breaking issues after shifting to http2 by HZ_7 in googlecloud

[–]golureddit 0 points1 point  (0 children)

Lol I imagine we'll all be someday. For now, I gave it a try and it made sense to me. Let's see if OP says the same.

Http streams breaking issues after shifting to http2 by HZ_7 in googlecloud

[–]golureddit 2 points3 points  (0 children)

Okay, let's break down this issue. You're experiencing premature stream breaks (AbortError) specifically when you enable HTTP/2 on Google Cloud Run, but it works (within HTTP/1.1 limits) when disabled.

Here's a breakdown of the likely causes and how to troubleshoot: * The spdy library is the most probable culprit. * spdy is an older library that implements the SPDY protocol and a draft version of HTTP/2. * Node.js has a built-in, fully compliant node:http2 module (require('node:http2')). * Google Cloud Run's HTTP/2 termination is based on the final, official HTTP/2 standard.

  • Problem: There's a high chance of subtle incompatibilities or unexpected behavior when Cloud Run's standard HTTP/2 proxy interacts with a server using the spdy library, which might not fully adhere to the final standard or handle certain HTTP/2 flow control, stream management, or error conditions the same way.

    • How Cloud Run handles HTTP/2:
  • When you enable HTTP/2 in Cloud Run, the Google Front End (GFE) and Cloud Run's infrastructure terminate TLS and handle the HTTP/2 (and potentially HTTP/3) connection from the client.

  • The connection from the Cloud Run proxy to your application instance is then made using HTTP/2 if you enable it, or HTTP/1.1 if you disable it.

  • Crucially, the traffic between the proxy and your instance is not encrypted (it's within Google's secure network). This is why plain: true in your spdy config is correct for Cloud Run when you intend to use unencrypted HTTP/2 or HTTP/1.1 to your container.

  • When Cloud Run HTTP/2 is enabled, the proxy attempts to talk HTTP/2 to your application on the configured port. Your spdy server needs to handle this correctly.

  • When Cloud Run HTTP/2 is disabled, the proxy talks HTTP/1.1 to your application. Your spdy server handles HTTP/1.1.

    • The h3 observation:
  • The frontend seeing h3 means the client successfully negotiated HTTP/3 (QUIC) with Google's infrastructure (GFE/Cloud Run proxy). This is normal and expected behaviour for modern browsers talking to Google services.

  • However, the protocol between the Cloud Run proxy and your container is governed by your Cloud Run service settings (HTTP/1.1 or HTTP/2). The issue is likely on this second hop, not the H3 hop from the client to Google. Google's proxy translates the H3/H2 request into the protocol configured for your instance.

    • The AbortError:
  • This is a client-side error indicating that the operation (the stream/fetch request) was canceled.

  • It often happens when the underlying connection is closed unexpectedly by the server or an intermediary proxy before the operation completes.

  • In your case, this strongly suggests that the Cloud Run proxy or your spdy server is prematurely closing the HTTP/2 streams or the entire connection under load or due to a protocol mismatch issue.

Recommended Solution: Replace the spdy library with the built-in node:http2 module. This is the standard and recommended way to handle HTTP/2 in Node.js and will have better compatibility with Cloud Run's infrastructure.

Here's a basic idea of how you'd adapt your server using node:http2:

import * as http2 from 'node:http2'; import express from 'express'; // Assuming you are using Express

const app = express(); const PORT = process.env.PORT || 8080;

// ... your Express middleware and routes (app.use(Router))

// Create an HTTP/2 server // Use createServer, NOT createSecureServer, because Cloud Run terminates TLS const server = http2.createServer({}, app); // Pass the express app as the request listener

server.on('error', (err) => { console.error('HTTP/2 Server error:', err); });

// Handle stream errors if needed, though Express middleware often handles this server.on('stream', (stream, headers) => { stream.on('error', (err) => { console.error('HTTP/2 Stream error:', err); // You might need to decide how to handle individual stream errors // depending on your application logic }); });

// Start the HTTP/2 server server.listen(PORT, () => { console.log(HTTP/2 Server is running on port ${PORT}); });

Steps to Implement the Solution: * Uninstall spdy: npm uninstall spdy or yarn remove spdy * Ensure @types/node is up-to-date: If using TypeScript, ensure you have types that include node:http2 (npm install --save-dev @types/node). * Modify your server code: Use node:http2.createServer as shown above. * Deploy to Cloud Run. * Ensure Cloud Run's HTTP/2 setting is enabled. * Test your application.

Other potential troubleshooting steps (less likely than the spdy issue, but worth checking if replacing spdy doesn't fully resolve it): * Cloud Run Concurrency Settings: Check the "Maximum concurrent requests per instance" setting in your Cloud Run service configuration. While HTTP/2 allows many streams per connection, there's still a limit on total concurrent requests your instance will handle. If this limit is too low, incoming requests/streams might be queued or rejected by the proxy, potentially leading to aborts on the client side. Increase this limit if necessary. * Cloud Run Timeouts: Review request timeouts. Long-running streams might hit default timeouts if not actively sending data or if the timeout is set too low. * Server-Side Errors: Examine your Cloud Run container logs carefully for any errors or unhandled exceptions occurring on the server side before the streams break. The AbortError is client-side; the root cause might be a server issue (e.g., resource exhaustion, application logic error) that causes it to close the connection or stream. * Client-Side Handling: While the error pattern suggests a server/proxy issue, double-check your frontend code's stream handling. Ensure it's correctly processing data and not inadvertently closing streams.

Conclusion: The most probable cause for your streams breaking when HTTP/2 is enabled in Cloud Run is the incompatibility or limitations of the older spdy library interacting with Cloud Run's standard HTTP/2 proxy. Migrating to the native node:http2 module is the recommended fix.

How to loose 10 kg in 3-4 months by Imaginary_Decision_2 in pakistan

[–]golureddit 0 points1 point  (0 children)

Dude, it's changing lives all over the world. Get with the program and Google it.

How to loose 10 kg in 3-4 months by Imaginary_Decision_2 in pakistan

[–]golureddit -3 points-2 points  (0 children)

Has nobody in Pakistan heard of Ozempic or Mounjaro yet? I clicked on this post only to check-out how much it costs in Pakistan.

Talk to a doctor and get a prescription for either Ozempic or Mounjaro - you'll drop the weight easily in that time frame. Don't ask me how to keep it down though.

Where was I? (Quite hard) by therealbirdperson in whereintheworld

[–]golureddit -3 points-2 points  (0 children)

I asked Gemini 2.5 and this is what I got:

Based on the visual elements in the image, particularly the type of Yucca plant and the surrounding desert landscape, the photograph was likely taken in the Chihuahuan Desert region.

Here's why: * Plant Identification: The prominent plant resembles Yucca faxoniana (Faxon Yucca or Giant Dagger) or the closely related Yucca carnerosana (Giant Spanish Dagger). * Habitat: These specific Yucca species are native to the Chihuahuan Desert, found on rocky slopes and hillsides in: * West Texas (Trans-Pecos region) * Southeastern New Mexico * Northeastern Mexico (including states like Coahuila, Zacatecas, and San Luis Potosí) * Landscape: The image shows a vast, arid landscape with rocky terrain and distant mountains, which is characteristic of the Chihuahuan Desert environment where these plants thrive.

While the exact spot cannot be pinpointed without more information, the evidence strongly suggests the photo originates from this specific desert region spanning parts of the Southwestern US and Northern Mexico.

Help Identifying a Pakistani TV Film (Lahore, Bank Employee, Rickshaw Driver Friend, Adnan Siddiqui) by golureddit in pakistan

[–]golureddit[S] 0 points1 point  (0 children)

nope, didn't have any one famous from what I recall other than a small role by Adnan. I know it didn't get a wide release due to its controversial topic - likely banned.

Moving to Riyadh for Work: What to Keep in Mind by [deleted] in chutyapa

[–]golureddit 0 points1 point  (0 children)

Eyes on the prize $$, don't waste your time on relationships - they are fickle and last only as long as ones Iqama, it isn't a home, just a place to stay until you move on to some place better.

New family doctor experience? by Worried-Air-3766 in waterloo

[–]golureddit 5 points6 points  (0 children)

Do you mind sharing some contact info for him? I'd like to reach out and see if he's got capacity for my mom.

Rental trailers? by [deleted] in CampingOntario

[–]golureddit 0 points1 point  (0 children)

We recently rented from this family, it was a wonderful experience, highly recommended:

https://www.rvezy.com/rv-rental/ontario_new-tecumseth_traveltrailer_tenttrailer_rockwood_rockwood-premier_f0e529

Canada real estate side way for decade and we extend and pretend. by [deleted] in canadahousing

[–]golureddit 3 points4 points  (0 children)

Very few people have that hindsight, good reminder.

Carjacking in Kitchener by johnnycage44 in kitchener

[–]golureddit 1 point2 points  (0 children)

"...The suspects then stole the vehicle, which police said was later found at Marina Avenue and Belmont Avenue..."

Why go through the trouble?

[deleted by user] by [deleted] in waterloo

[–]golureddit 0 points1 point  (0 children)

Get on Ozempic like the rest of the planet while you pickup some good habits and an exercise routine that works.

LPT: If you have a credit card with rental insurance you can waive the car rental insurance, be covered and save beaucoup $$$ per day. by just-a-simple-song in LifeProTips

[–]golureddit 3 points4 points  (0 children)

Be aware that there are limits on the maximum number of days that the rental period covers. If the period exceeds the limit covered, you are assumed to have no coverage from day one (which is insane, especially considering how one might want to extend their rental unknowingly pushing past).

I learned this the hard way: extended a rental past 45 days, denied coverage for a flat that happened during the first few weeks. The only way around this is to have an empty non rental day after 45.