Memory exhaustion after some time
Author: dsuarezvCreated Apr 6, 2022Updated Jul 14, 2025
Issue details
Hi there,
I'm finding that browser-sync crashes because of memory exhaustion after a day or two running continuously. Here is the stack trace I get:
...
[Browsersync] Reloading Browsers...
[Browsersync] Reloading Browsers...
<--- Last few GCs --->
[2982:0x624d7c0] 66051559 ms: Mark-sweep (reduce) 2044.4 (2081.8) -> 2043.7 (2082.1) MB, 1055.1 / 10.8 ms (average mu = 0.537, current mu = 0.018) allocation failure scavenge might not succeed
[2982:0x624d7c0] 66053046 ms: Mark-sweep (reduce) 2044.7 (2082.1) -> 2044.1 (2082.3) MB, 1478.2 / 8.3 ms (average mu = 0.320, current mu = 0.006) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0xb09980 node::Abort() [gulp]
2: 0xa1c235 node::FatalError(char const*, char const*) [gulp]
3: 0xcf77be v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [gulp]
4: 0xcf7b37 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [gulp]
5: 0xeaf3d5 [gulp]
6: 0xebf09d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [gulp]
7: 0xec1d9e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [gulp]
8: 0xe832da v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [gulp]
9: 0x11fc026 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [gulp]
10: 0x15f0a99 [gulp]
Aborted (core dumped)
The machine is Linux 64bits running Ubuntu 21.
I don't know if it's related, but I'm including images and reloading if they change, maybe this is contributing to exhaust the memory more quickly. The images don't change very often, however.
I had core dumps disabled, I can enable them and send the dump if you need it.
Steps to reproduce/test case
See gulp script below. Just leave it running for a full day making changes here and there, it's crashed in the morning.
Please specify which version of Browsersync, node and npm you're running
- Browsersync: [2.27.9]
- Node: [16.14.0]
- Npm: [8.3.1]
Affected platforms
- linux
- windows
- OS X
- freebsd
- solaris
- other (please specify which)
Browsersync use-case
API
Gulp
CLI
Grunt
for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync
var browserSync = require( 'browser-sync' ).create();
var gulp = require( 'gulp' );
var paths = {
php: [ '*.php', '**/*.php' ],
scripts: [ 'js/*.js', '*.js' ],
styles: [ '*.css', 'css/*.css' ],
images: [ '*.png', '*.jpg' ]
};
gulp.task( 'default', function() {
browserSync.init({
proxy: 'http://n1587.xxxxxxxxxx.com',
host: 'n1587.xxxxxxxxxx.com',
open: 'external',
port: 8000
});
gulp.watch( paths.php ).on( 'change', browserSync.reload );
gulp.watch( paths.scripts ).on( 'change', browserSync.reload );
gulp.watch( paths.images ).on( 'change', browserSync.reload );
gulp.watch( paths.styles ).on('change', function() {
gulp.src( paths.styles ).pipe( browserSync.stream() );
});
});Source: BrowserSync/browser-sync