Use a more conservative message size, and properly account for URI encoding

This commit is contained in:
Pablo Carranza Velez 2016-08-31 16:28:42 +00:00
parent 78b4570b93
commit ec178f7a7f

View File

@ -10,7 +10,7 @@ LOG_PUBLISH_INTERVAL = 110
# Pubnub's message size limit is 32KB (unclear on whether it's KB or actually KiB, # Pubnub's message size limit is 32KB (unclear on whether it's KB or actually KiB,
# but we'll be conservative). So we limit a log message to 2 bytes less to account # but we'll be conservative). So we limit a log message to 2 bytes less to account
# for the [ and ] in the array. # for the [ and ] in the array.
MAX_LOG_BYTE_SIZE = 31998 MAX_LOG_BYTE_SIZE = 30000
MAX_MESSAGE_INDEX = 9 MAX_MESSAGE_INDEX = 9
disableLogs = false disableLogs = false
@ -60,7 +60,7 @@ publish = do ->
_.defaults message, _.defaults message,
t: Date.now() t: Date.now()
m: '' m: ''
msgLength = Buffer.byteLength(JSON.stringify(message), 'utf8') msgLength = Buffer.byteLength(encodeURIComponent(JSON.stringify(message)), 'utf8')
return if msgLength > MAX_LOG_BYTE_SIZE # Unlikely, but we can't allow this return if msgLength > MAX_LOG_BYTE_SIZE # Unlikely, but we can't allow this
remaining = publishQueueRemainingBytes - msgLength remaining = publishQueueRemainingBytes - msgLength
if remaining >= 0 if remaining >= 0