GithubHelp home page GithubHelp logo

Crash randomly.. about nanoexpress HOT 15 CLOSED

nanoexpress avatar nanoexpress commented on May 18, 2024
Crash randomly..

from nanoexpress.

Comments (15)

dalisoft avatar dalisoft commented on May 18, 2024

Hi @MrBot45
Thanks for trying out nanoexpress and i'm happy to help here to you, but should create minimal reproducible repo to test.

from nanoexpress.

 avatar commented on May 18, 2024

What do you mean?

from nanoexpress.

 avatar commented on May 18, 2024

Im using nanoexpress as a middleware proxy. It have a lot of bugs but I can't find a solution around for this bug. It seems like the internal fails.

from nanoexpress.

 avatar commented on May 18, 2024

Go on this page to get the error: https://bobuxpvp.tk/login

Enter anything, it always throw an error. It work fine with express so im not sure what's the issue.

from nanoexpress.

dalisoft avatar dalisoft commented on May 18, 2024

What do you mean?

Minimal reproducible repository and/or example, read here to test and fix.

Im using nanoexpress as a middleware proxy. It have a lot of bugs but I can't find a solution around for this bug. It seems like the internal fails.

Please create separate issue for every bug, i'll look and fix as i can. Also, please don't use nanoexpress as a middleware, just use as Server framework without other frameworks :)

from nanoexpress.

dalisoft avatar dalisoft commented on May 18, 2024

Go on this page to get the error: https://bobuxpvp.tk/login

Enter anything, it always throw an error. It work fine with express so im not sure what's the issue.

I see, but i need MRE/MRR to test and know where it fails and fix.

from nanoexpress.

 avatar commented on May 18, 2024

Idk how to reproduce the issue.. It's just a reverse proxy..

from nanoexpress.

dalisoft avatar dalisoft commented on May 18, 2024

Idk how to reproduce the issue.. It's just a reverse proxy..

Thanks for describe how you use. Do you using proxy (example) define to use as reverse proxy?

from nanoexpress.

 avatar commented on May 18, 2024

No. My project has over 2k lines of code it's hard to provide a minimal example. It require extenal database and stuff.

this.app = nanoexpress();
		
		this.app.setErrorHandler((e, r, s) => {
			console.log(e.stack);
			s.json({error: e.stack});
		}); 
this.app.any('/*', async (req, res) => { // cant use async for no reason so had to make a custom next function because this never return a "next" parameter
			this.process(req, res, () => {
				this.next(req, res);
			});
		});

//Method process
proxy(`${await this.getEndPoint(host)}${reqUrl}`, {
				proxyErrorHandler: (err, res, next) => {
					console.error('Endpoint errored! Status code:', err);
					res.status(507).end(this.errorPage.replace('"Origin"', host || 'unknown host'));
				}
			})(req, res, next);

// Proxy.js

Please fix your write stream they are buggy. I cant get video streaming to work normaly so i had to create my own write stream (see https://bobuxpvp.tk/video2.webm)
let dest = new Stream();
		dest.writable = true;
		dest.byteLength = 0;
		dest.finalSize = 0;
		dest.start = Date.now();
		dest.chunks = [];
		dest.write = (chunk) => {
			try {
				if(g) clearTimeout(g);
				let chunk_ = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
				
				dest.byteLength += chunk_.byteLength;
			
				if(dest.finalSize > 15000000) {
					res.write(chunk_);
				} else {
					dest.chunks.push(chunk_);
				}
			} catch(e) {
				console.log(e);
			}
		}
		
		dest.end = () => {
			console.log('Took ' + (Date.now() - res.startTime) + 'ms', 'Stream end. Bytes:', dest.byteLength, url, dest.finalSize, dest.chunks.length, dest.finalSize > 15000000);
			
			try {
				if(dest.finalSize > 15000000) {
					res.end('');
				} else {
					res.end(Buffer.concat(dest.chunks));
				}
			} catch(e) {
				console.log(e);
			}
			dest.chunks = [];
		}
		
		res.onAborted((e) => {
			console.log('Aborded', url);
			dest.chunks = [];
			errored = true;
		});

let proxiedReq = http.request(options, (res_) => {
			res.cork(() => {
				if(errored) return;


// [...]

if(!errored) res_.pipe(dest);

} [...]```

from nanoexpress.

dalisoft avatar dalisoft commented on May 18, 2024

Seems your proxy function as middleware working wrong.

Crash on POST request.
TypeError: stream.on is not a function
+ at readStream (/root/middleware/node_modules/raw-body/index.js:190:10)
+ at getRawBody (/root/middleware/node_modules/raw-body/index.js:108:12)
+ at read (/root/middleware/node_modules/body-parser/lib/read.js:77:3)
+ at urlencodedParser (/root/middleware/node_modules/body-parser/lib/types/urlencoded.js:116:5)
at /root/middleware/node_modules/nanoexpress-pro/cjs/nanoexpress.js:1718:17
at new Promise ()
at middleware (/root/middleware/node_modules/nanoexpress-pro/cjs/nanoexpress.js:1717:22)
at handler (/root/middleware/node_modules/nanoexpress-pro/cjs/nanoexpress.js:1910:40)

Before nanoexpress these modules are crashing, so checkout proxy define to make proxy easier and high-performant.

Thanks

from nanoexpress.

 avatar commented on May 18, 2024

Will check it out, can you try to fix the write stream? I have to make a check for the buffer size to see if it's smaller than 15mb or it's just abording everytime. Even with this bypass, it's flooding the logs with

Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse

from nanoexpress.

 avatar commented on May 18, 2024

The stream end itself while writing data.

from nanoexpress.

dalisoft avatar dalisoft commented on May 18, 2024

@MrBot45
Then you using async or stream wrong.

As issue creation requires

If this issue not related to this project and exists on core of this project, please close issue or not open

core of this project does not handle these wraps, but nanoexpress does, but it does not mean it does all magic like express, that's why expressjs almost 8x slower than nanoexpress.

My library isn't great, but you should first checkout examples folder as available some examples how do something correctly.
As it's your code issue, i should close issue and then continue in closed status.

If you need premium contact support to fix this, then contact to me via [email protected] or at Telegram

from nanoexpress.

 avatar commented on May 18, 2024

Is it possible to add a next function to setErrorHandler? I want to continue the request even if it get errored. Like express : app.use((err, req, res, next) => {

from nanoexpress.

dalisoft avatar dalisoft commented on May 18, 2024

Yep, it is possible. But always you can use 3 argument, not 4. Check examples and documentations please

from nanoexpress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.