Ionic Cordova Barcode Scanner works for iOS but not Android - jquery-mobile

I have an app that has the Cordova Barcode Scanner to scan the UPC number. It works fine on iOS and returns the results as expected. However on Android Marshmallow 6.1 it scans and shows the message Product found on the camera screen but doesn't return any values to my view as expected. I have scanned through my entire app and no where I have the text Product found. Not sure what is the source of this message. Please help.
Problem persists on Android 5.1 as well.
You can see this Product found message. I have search through my app code as well as the code for my apis. None works. Please see the URL below:
https://drive.google.com/open?id=0B81YQAjfP0R2VmU2V1I1QTg3NWc
Also see the iOS version of it that is fully functional:
https://drive.google.com/open?id=0B81YQAjfP0R2RkhEeVlOVUlLUmc
Please see the debug code below. nothing is published in the console when barcode scanner is called.
D/PowerManagerService( 946): turnOffButtonLight mButtonLightTimeout = 2000
D/PowerManagerService( 946): Trun on the button and after 2000s,then turn off the button !
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 9.0
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 14.0
D/PowerManagerService( 946): turnOffButtonLight mButtonLightTimeout = 2000
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 3.0
D/PowerManagerService( 946): Trun on the button and after 2000s,then turn off the button !
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 12.0
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 9.0
D/PowerManagerService( 946): turnOffButtonLight mButtonLightTimeout = 2000
D/ConnectivityService( 946): updateNetworkScore for NetworkAgentInfo [WIFI () - 109] to 51
D/ConnectivityService( 946): rematching NetworkAgentInfo [WIFI () - 109]
D/ConnectivityService( 946): Network NetworkAgentInfo [WIFI () - 109] was already satisfying request 1. No change.
D/ConnectivityService( 946): notifyType AVAILABLE for NetworkAgentInfo [WIFI () - 109]
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 11.0
D/PowerManagerService( 946): Trun on the button and after 2000s,then turn off the button !
I/ActivityManager( 946): START u0 {act=com.google.zxing.client.android.SCAN cat=[android.intent.category.DEFAULT] pkg=com.test.testapp296079 cmp=com.test.testapp296079/com.google.zxing.client.android.CaptureActivity} from uid 10110 on display 0
V/WindowManager( 946): addAppToken: AppWindowToken{2ac1f12b token=Token{2571457a ActivityRecord{1e190da5 u0 com.test.testapp296079/com.google.zxing.client.android.CaptureActivity t35}}} to stack=1 task=35 at 1
V/WindowManager( 946): Adding window Window{2ec02634 u0 com.test.testapp296079/com.google.zxing.client.android.CaptureActivity} at 9 of 13 (after Window{3d1aa37b u0 com.test.testapp296079/com.test.testapp296079.MainActivity})
V/WindowManager( 946): Adding window Window{2c8f09d2 u0 SurfaceView} at 9 of 14 (before Window{2ec02634 u0 com.test.testapp296079/com.google.zxing.client.android.CaptureActivity})
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 9.0
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 17.0
D/PowerManagerService( 946): turnOffButtonLight mButtonLightTimeout = 2000
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 8.0
D/AutomaticBrightnessController( 946): ZTE_PM_LIGHT updateAmbientLux: mLightSensorListener lux is 110.0
D/AutomaticBrightnessController( 946): updateAutoBrightness: value=0.16730924 *255 = 42.663857
D/AutomaticBrightnessController( 946): updateAutoBrightness: mScreenAutoBrightness=21, newScreenAutoBrightness=43
D/DisplayPowerController( 946): ZTE_PM updatePowerState mPowerRequest.dozeScreenState=0
D/DisplayPowerController( 946): ZTE_PM_PROX updatePowerState state=2
D/DisplayPowerController( 946): ZTE_PM_PROX disable ProxSensor while NO useProximitySensor
D/AutomaticBrightnessController( 946): ZTE_PM mScreenAutoBrightnessAdjustment no change
D/AutomaticBrightnessController( 946): shuangdan LightSensorchanged = true,autolcdenable = true,autobuttonEnabled = false
D/AutomaticBrightnessController( 946): updateAutoBrightness: value=0.16730924 *255 = 42.663857
D/DisplayPowerController( 946): ZTE_PM_LHX_animate mPowerState.getScreenBrightness() 21 mPowerState.getActualScreenBrightness() 21
D/DisplayPowerController( 946): ZTE_PM_animate animate LCD brightness to 43

Alright, this was really being the Android first timer issue.
Turns out a very silly issue that is OS specific caused it to fail. iOS handles false as a 0 and android as a text string false. I just had to put this condition and it worked.
if($scope.cancelled === 0 || $scope.cancelled === false)

Related

iOS application is getting crashed if we continuously publish / unpublish the audio and video track, TwillioVideo SDK

Description
in my application I am publishing and unpublishing the audio and video tracks when user mute / unmute audio and enable / disable the camera. After 2 three continues tap the application is getting crashed.
I tried to disable the mic button interaction until the audio is not published, as we get callback in localParticipantDidPublishAudioTrack but for un-publish there is no callback. That logic is also crashing. How can I fix this crash
Also please suggest what will be the side effect if I will enable/disable the audio track instead of publish / unpublish. Also what is the recommended approach for both audio and video
Steps to Reproduce
While on the call try monkey tap on mute button and from the code inside publish & unpublish the audio track on each respective tap
Code
#IBAction func micControlAction(_ sender: Any) {
//Toggle mic
guard let participant = callViewModel.getCallParticipant(type: .patient) else { return }
if let audioTrack = participant.audioTrack as? LocalAudioTrack {
if audioTrack.isEnabled {
(participant.participant as? LocalParticipant)?.unpublishAudioTrack(audioTrack)
}
else {
(participant.participant as? LocalParticipant)?.publishAudioTrack(audioTrack)
}
audioTrack.isEnabled = !audioTrack.isEnabled
//This will call the observer and the UI will gets updated according to the need
participant.micEnabled.property = audioTrack.isEnabled
}
}
Expected behavior: The user should be able to mute / unmute the mic without any delay.
Actual behavior: Application crashes 100% of time
Logs
libc++abi.dylib: Pure virtual function called!
Pure virtual function called!
Versions
Video iOS SDK 4.6.0 via CocoaPods
Xcode 13.1
iOS Version 13.6.1
iOS Device iPad Air
Based on suggestion on this link, it seems that TwillioVideo 4.6.0 SDK is having issue and reverting to TwillioVideo SDK to version 4.4.0 works fine.
The crash log when using version 4.6.0:
Thread 31 name:
Thread 31 Crashed:
0 libsystem_kernel.dylib 0x00000001ba0e39c4 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001f3333434 pthread_kill + 268 (pthread.c:1609)
2 libsystem_c.dylib 0x000000018e562f64 abort + 164 (abort.c:118)
3 libc++abi.dylib 0x000000019bd89bc4 abort_message + 132 (abort_message.cpp:78)
4 libc++abi.dylib 0x000000019bd89594 __cxa_pure_virtual + 24 (cxa_virtual.cpp:16)
5 TwilioVideo 0x0000000105686668 0x104fe4000 + 6956648
6 TwilioVideo 0x000000010568646c 0x104fe4000 + 6956140
7 TwilioVideo 0x0000000105420e0c 0x104fe4000 + 4443660
8 TwilioVideo 0x0000000105420db4 0x104fe4000 + 4443572
9 TwilioVideo 0x0000000105499924 0x104fe4000 + 4938020
10 TwilioVideo 0x0000000105499188 0x104fe4000 + 4936072
11 TwilioVideo 0x0000000105498128 0x104fe4000 + 4931880
12 TwilioVideo 0x0000000105499568 0x104fe4000 + 4937064
13 libsystem_pthread.dylib 0x00000001f332da60 _pthread_start + 148 (pthread.c:890)
14 libsystem_pthread.dylib 0x00000001f332cf5c thread_start + 8

Segmentation fault: 11 - Xcode/Swift 5 compile issue

I'm always getting a Segmentation fault: 11 error when compiling.
I have massively stripped back my code to identify the nuances of what is causing the issue and have produced the demo code below that exhibits the exact same problem.
Can anyone suggest any way to resolve this issue (thats different to what I have already highlight in the code comments)?
PS: this Swift 5 code and occurs with both Xcode 11.7 and Xcode 12
// If we make this a class instead, it compiles! (but I want it to be a struct)
struct SomeStruct {
// If we remove either of these properties or change them to an Int, it compiles! (but I obviously need 2 strings)
let propertyA: String
let propertyB: String
}
protocol Protocol { }
enum Enumeration {
// If we remove this case, it compiles! (but I need this case, and the protocol also)
case possibilityA(protocol: Protocol)
// If we add additional associated values to this case, it compiles! (but I need this case)
case possibilityB(completion: (Result<SomeStruct, Error>) -> ())
}
class SomeClass {
func method() {
// If we remove the use of `possibilityB`, it compiles! (but I need this)
_ = Enumeration.possibilityB(completion: { _ in
})
}
}
Here's the stack dump...
Stack dump:
0. Program arguments: /Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/x/Demo/Sources/Demo/Demo.swift -emit-module-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftmodule -emit-module-doc-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftdoc -emit-module-source-info-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftsourceinfo -serialize-diagnostics-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.dia -emit-dependencies-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.d -emit-reference-dependencies-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.swiftdeps -target arm64-apple-ios9.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk -I /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos -I /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos -F /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/x/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/x/Demo -enable-anonymous-context-mangled-names -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/swift-overrides.hmap -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos/include -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources-normal/arm64 -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources/arm64 -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -target-sdk-version 14.0 -parse-as-library -module-name Demo -o /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.o -embed-bitcode-marker -index-store-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Index/DataStore -index-system-modules
1. Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2. While evaluating request IRGenSourceFileRequest(IR Generation for file "/Users/x/Demo/Sources/Demo/Demo.swift")
3. While emitting IR SIL function "#$s8Demo9SomeClassC6methodyyF".
for 'method()' (at /Users/x/Demo/Sources/Demo/Demo.swift:21:5)
4. While converting type '(#callee_guaranteed (#in_guaranteed Result<SomeStruct, Error>) -> ())'
0 swift 0x0000000107a19865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1 swift 0x0000000107a18865 llvm::sys::RunSignalHandlers() + 85
2 swift 0x0000000107a19e1f SignalHandler(int) + 111
3 libsystem_platform.dylib 0x00007fff68acc5fd _sigtramp + 29
4 libsystem_platform.dylib 0x0000000000000004 _sigtramp + 18446603338760010276
5 swift 0x00000001039794d8 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 21400
6 swift 0x000000010396fc26 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8982
7 swift 0x0000000103809dc7 swift::irgen::IRGenerator::emitGlobalTopLevel(llvm::StringSet<llvm::MallocAllocator>*) + 1607
8 swift 0x00000001039449d7 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1687
9 swift 0x000000010396d681 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
10 swift 0x0000000103948dec llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 940
11 swift 0x000000010394503d swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
12 swift 0x0000000103590d3a performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3002
13 swift 0x0000000103580928 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 20712
14 swift 0x0000000103501c07 main + 1255
15 libdyld.dylib 0x00007fff688d3cc9 start + 1
16 libdyld.dylib 0x000000000000004f start + 18446603338762077063
error: Segmentation fault: 11 (in target 'Demo' from project 'Demo')
Naming the enum associated values is a shadow zone. While it is apparently accepted under certain conditions, it is not used or even mentioned in the official Swift Language Guide chapter on Enumerations. So in this case, your code compiles fine if you remove the naming.
enum Enumeration {
case possibilityA(Protocol)
case possibilityB((Result<SomeStruct, Error>) -> ())
}
...
func method() {
let _ = Enumeration.possibilityB({ _ in
})
In any case, a crashing compiler is never nice, no matter how bad code you feed it, and furthermore you got a pretty cool minimal test, so filling a report should be your duty and honor :)

SpeechKit SDK (Dragon Mobile) - Crash on Initialization

We have a repeating crash when initilizing Speechkit.
It only happens sometimes on both iOS7 & iOS8 and we could not identify a specific scenario.
We were using ver. 1.0.3 and upgraded to 1.4.12. This issue happens in both versions.
The trace looks like:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000
Thread : Crashed: com.apple.main-thread
0 CoreFoundation 0x25521ca4 CFArrayGetCount + 23
1 24me 0x00548de1 -[TAGPValue(Hash) hash]
2 24me 0x00548de1 -[TAGPValue(Hash) hash]
3 24me 0x00548bf3 -[TAGPValue(Hash) hash]
4 24me 0x00548513 -[TAGPValue(Hash) hash]
5 24me 0x0054b6a9 -[TAGPValue(Hash) hash]
6 24me 0x0038ab17 -[ViewController setupTextToSpeechInterface] (ViewController.m:1370)
7 24me 0x0037a481 -[ViewController viewDidLoad] (ViewController.m:196)
//this is the method we use to initialise
-(void)setupTextToSpeechInterface{
if (![SpeechKit sessionID]) {
[SpeechKit setupWithID:#"XXXXXXXXXXXX"
host:#"ti.nmdp.nuancemobility.net"
port:443
useSSL:NO
delegate:nil];
}
}

Space between the last 2 lines of a paragraph is larger?

I draw the text using CTFramesetter, I have set kCTParagraphStyleSpecifierParagraphSpacing, kCTParagraphStyleSpecifierLineSpacing, kCTParagraphStyleSpecifierParagraphSpacingBefore all to 0.0.
As you can see in the image, the space between the last 2 lines of a paragraph is much larger than others'.
There're in total 15 lines in this image, I pasted their ascent, descent, leading, origin.y in the following, we can see that the ascent and descent on the 5th and 10th line are larger than others', I couldn't find any specifier to set to avoid this weird layout.
Any ideas?
1 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 399.000000
2 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 374.000000
3 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 349.000000
4 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 324.000000
5 ascent=25.722656, desecent=13.699219, leading=0.720000, origin.y: 294.000000
6 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 258.000000
7 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 233.000000
8 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 208.000000
9 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 183.000000
10 ascent=25.722656, descent=13.699219, leading=0.720000, origin.y: 153.000000
11 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 117.000000
12 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 92.000000
13 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 67.000000
14 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 42.000000
15 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 17.000000
If you use NSMutableAttributeString for text layout, you can set a CTRunDelegate attribute to set the \n metrics to 0. For me this worked:
CTRunDelegateCallbacks callbacks;
callbacks.version = kCTRunDelegateVersion1;
callbacks.getAscent = lineBreakCallback;
callbacks.getDescent = lineBreakCallback;
callbacks.getWidth = lineBreakCallback;
CTFontRef fontRef = CTFontCreateWithName((CFStringRef)#"System", 1.0f, NULL);
CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, NULL); //3
NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:
//set the delegate
(__bridge id)delegate, (NSString*)kCTRunDelegateAttributeName,
(__bridge id)fontRef, kCTFontAttributeName,
nil];
stringLength++;
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:#"\n" attributes:attrDictionaryDelegate]];
CFRelease(delegate);
CFRelease(fontRef);
and
static CGFloat lineBreakCallback( void* ref )
{
return 0;
}
EDIT:
following comments I fixed memory management part (I hope that correctly)
I added a font attribute with font of size 1. This is because when the font size of a run (default font size is about 16) is bigger than the rest of line, it changes the line metrics even if the run metrics are smaller (which is quite annoying if you really want to set a bigger font size to a part of a line without for example changing the line's descent - I haven't found a solution for this problem yet).
Damit, it's a bug. DTCoreText works around this by repositioning the baseline origins of those affected lines.
see http://www.cocoanetics.com/2012/02/radar-coretext-line-spacing-bug/

NodeJS 0.3.1 app leaking memory

I've got a fairly simple NodeJS app that is nothing but a shell that accepts requests and parses content using a form of Readability (based on https://github.com/arrix/node-readability). The problem is that I've noticed the app leaks memory - I've run node --trace-gc and the memory slowly builds up with each request with the occasional gc pass doing nothing.
$ node --trace-gc server.js
Scavenge 2.3 -> 2.3 MB, 1 ms.
Mark-sweep 3.5 -> 2.9 MB, 2 ms.
Scavenge 4.4 -> 3.8 MB, 0 ms.
16 Feb 10:57:51 - Server started on PORT 8000
Scavenge 5.9 -> 5.0 MB, 2 ms.
Mark-sweep 5.0 -> 4.2 MB, 3 ms.
Mark-compact 4.2 -> 4.1 MB, 7 ms.
Scavenge 5.2 -> 4.7 MB, 1 ms.
Scavenge 5.5 -> 5.1 MB, 1 ms.
Scavenge 5.9 -> 5.5 MB, 1 ms.
Scavenge 7.1 -> 6.3 MB, 2 ms.
Scavenge 7.8 -> 7.0 MB, 2 ms.
Mark-sweep 8.5 -> 7.6 MB, 10 ms.
Scavenge 11.7 -> 9.7 MB, 4 ms.
Scavenge 12.7 -> 11.2 MB, 5 ms.
Mark-sweep 14.2 -> 12.4 MB, 21 ms.
Scavenge 20.5 -> 16.5 MB, 10 ms.
Scavenge 22.5 -> 19.5 MB, 11 ms.
Mark-sweep 25.5 -> 22.4 MB, 38 ms.
Scavenge 36.6 -> 29.6 MB, 25 ms.
Scavenge 41.6 -> 35.6 MB, 24 ms.
Mark-sweep 46.8 -> 41.1 MB, 75 ms.
Scavenge 46.8 -> 44.0 MB, 33 ms.
Mark-sweep 57.2 -> 50.6 MB, 92 ms.
Scavenge 62.3 -> 56.5 MB, 26 ms.
Scavenge 68.5 -> 62.6 MB, 24 ms.
Scavenge 74.6 -> 68.6 MB, 26 ms.
Mark-sweep 80.6 -> 74.5 MB, 130 ms.
Scavenge 80.5 -> 77.6 MB, 25 ms.
Mark-sweep 77.6 -> 77.4 MB, 112 ms.
Mark-compact 77.4 -> 77.4 MB, 260 ms.
Even after the requests stop and the GC has time to run over and over the memory usage does not decrease.
I'm more or less convinced that I must be assigning a global variable somewhere but I can't figure out how to fix it. The code for this project lives here:
https://github.com/erskingardner/Readable
Does anyone have any suggestions (and reasoning) of what I should do?
I'll answer my own question here in hopes that it might help out other people with the same issue.
The problem was actually to do with the event.emitter's I'd used in creating the server. When just a single connection was being used there was no memory leak (think development) but when the app started to get hit a lot memory started to climb and climb and the GC wasn't doing anything. I had placed an event listener one step too high in the chain and because of that I was creating an event listener that was never being destroyed.
==
BROKEN CODE
Readable.prototype.createHTTPServer = function() {
var self = this;
var server = http.createServer(function(request, response) {
request.addListener('end', function() {
var location = url.parse(request.url, true)
,params = (location.query || request.headers)
,body = "";
if (location.pathname == '/' && request.method == "GET"){
if (params["url"] == null){
response.writeHead(200, {
'Content-Type': 'text/html'
});
response.end("Good to go, you might want to try adding a url param though.");
}
else if (params["url"] != null){
self.fetchAndParse(params["url"], params);
}
var listener = emitter.on("readability", function(result) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
if (result == "error"){
response.end("error");
} else {
response.end(result.content);
}
});
}
});
});
return server
};
The listener variable was the part that was never being destroyed. I tried to force the delete of the variable but then the response was never making it to the browser. The answer was that all I had to do was move that listener var inside the else if statement and it was automatically GC'ed when the function was finished running.
==
PROPER CODE
Readable.prototype.createHTTPServer = function() {
var self = this;
var server = http.createServer(function(request, response) {
request.addListener('end', function() {
var location = url.parse(request.url, true)
,params = (location.query || request.headers)
,body = "";
if (location.pathname == '/' && request.method == "GET"){
if (params["url"] == null){
response.writeHead(200, {
'Content-Type': 'text/html'
});
response.end("Good to go, you might want to try adding a url param though.");
}
else if (params["url"] != null){
self.fetchAndParse(params["url"], params);
var listener = emitter.on("readability", function(result) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
if (result == "error"){
response.end("error");
} else {
response.end(result.content);
}
});
}
}
});
});
return server
};
Like PartlyCloudy mentioned you should really update your node.js instance to latest greatest v0.4.0. Hopefully the bug has been fixed, or if not you could submit an issue over at github.
I don't think Ryan's is going to fix any bugs with that old unstable version.

Resources