Divide and conquer- Lighttpd's mod_wstunnel combines separate messages by using UNIX socket communication to the backend server

In my experience with lighttpd's mod_wstunnel, I have encountered a peculiar issue. When I send two messages in quick succession from the backend using a UNIX socket to communicate between lighttpd and the backend, I noticed that lighttpd logs show that it receives these messages as a single combined message.

However, if there is even a minimal delay of 1ms between the two write calls to the UNIX socket, lighttpd receives the messages separately and forwards them as such to the final client.

To demonstrate this issue, I created a simple proof of concept setup:

The configuration file for lighttpd (which can be launched using lighttpd -D -f lighttpd-poc.conf):

server.document-root = var.CWD 
server.bind = "0.0.0.0" 
server.port = 8042 

... (additional configurations) ...

Furthermore, the HTML page being served where the problem manifests easily:

<!DOCTYPE html> 
<script> 
    ... (WebSocket setup script) ...
</script> 

And finally, the simplified backend code responsible for handling websocket requests:

#include <iostream> 
#include <thread> 
#include <chrono> 

using namespace std::chrono_literals; 

int main() 
{ 
    ... (backend setup) ...

    while (true) { 
        ... (logic for processing messages) ...
            // std::this_thread::sleep_for(1ms); // Uncommenting this line resolves the issue. 
            ... (sending second message) ...
        } 
    } 

    return 0; 
} 

It's worth noting that uncommenting the std::this_thread::sleep_for(1ms) line in the backend code eliminates the message combining issue. This problem leads to failed JSON parsing by the browser when navigating to the specified URL due to the merged messages being received.

While workarounds exist like utilizing libraries or including the sleep function in the code, identifying the root cause of this buffering phenomenon is crucial. Understanding why and where this buffering occurs in the kernel will provide insights into resolving the issue effectively. Additionally, exploring solutions beyond temporary fixes is essential for long-term stability and optimal performance.

If relevant, the version of lighttpd being used is 1.4.55.

Answer №1

One user suggested in a previous comment that the issue of concatenating JSON messages in lighttpd/mod_wstunnel is addressed by RFC 6455, which mentions that intermediaries may combine or separate frames.

lighttpd mod_wstunnel functions as a websocket tunnel that generates websocket frames from backend data without examining the content. This allows the backend to transmit data in various formats, such as JSON, with no consideration for message boundaries within the JSON structure.

An alternative approach involves utilizing lighttpd mod_proxy with modifications to lighttpd.conf using

proxy.header += ("upgrade" => "enable")
. By implementing the websocket protocol at the proxy backend, you can take control over the websocket framing process.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leaflet setStyle changes are effective when applied through the console but do not reflect in the actual

I currently have a map with around 1000 polygons that I am loading onto it. My goal is to color these polygons based on a specific property value. The code snippet below showcases my approach, but the results are not as expected. mapLayerFieldGrid = new L ...

Unable to modify the properties of a stateless child component

I'm completely new to React and I decided to create a basic comments application. My main objective was to let users change their display pictures by clicking the 'Change Avatar' button. However, I encountered an issue where the 'Chang ...

Issue with javascript code not functioning post axios request

When working on my project, I utilize axios for handling Ajax requests. I crafted a script that attaches a listener to all links and then leverages Axios to make the Ajax request. Following the Ajax request, I aim to execute some post-processing steps. Aft ...

Ways to transfer a value from a JavaScript file to a PHP file?

Is there a way to transfer data from a JavaScript file to a PHP file? Code: var year = (year != null) ? year : '".$this->arrToday["year"]."'; var month = (month != null) ? month : '".$this->ConvertToDecimal($this>arrTod ...

Issues with Angular JS page loading when utilizing session and local storage in Google Chrome

I'm currently learning about AngularJS and I stumbled upon this helpful tutorial http://embed.plnkr.co/dd8Nk9PDFotCQu4yrnDg/ for building a simple SPA page. Everything was working smoothly in Firefox and IE, except when it came to using Local and Sess ...

JSON auto complete problem

Below is my webservice method: <WebMethod()> _ Public Function TravelMeansList(ByVal prefix As String) As List(Of HRM_travellingMeans) Dim ctx As New HRMEntities Dim query = From c In ctx.HRM_travellingMeans Where c.name.ToUpper ...

NodeJS not recognizing global variable causing it to return undefined

Can a global variable be defined in a node.js function? I wish to use the variable "ko" (declared in the getNumbers function) in other functions function getNumbers(callback) { result = cio.query("SELECT numbers FROM rooms WHERE durum='1'", ...

Exploring the benefits of looping with node.js require()

Currently, I have defined the required files as shown below. constantPath = './config/file/' fileAA = require(path.resolve(constantPath + 'A-A')), fileBB = require(path.resolve(constantPath + 'B-B')), fileCC = require(path.r ...

What is the correct way to specify the type in my functional component?

I was trying to define the type in my component in a different way, I know it can be done using classes but is there a way to achieve this with functional components without exporting the interface? Despite my extensive research, I couldn't find any r ...

Verify authentication on a SignalR console application using a JavaScript client

Here is the scenario and solution I am currently working on: In project one, I have a SignalR console application that handles the logic, including authentication using Entity Framework to query the database. In project two, I have an ASP.Net web applicat ...

Where should I place my .json file to integrate Google Sheets data into my Flask web app successfully?

I'm currently in the process of setting up a web application that pulls data from Google Sheets and presents it. I came across the idea after watching a video by Twilio, which I successfully implemented on my local machine. However, I am facing diffic ...

Issue encountered while retrieving information from XML file through AJAX

I am facing an issue while using AJAX to fetch data from an external XML file. The error I receive is "Invalid argument" and I am working with IE 8. Below is the code snippet: var xhr; xhr = new XMLHttpRequest(); xhr.open("GET","C:/Users/abc/Desktop/Pr ...

Printing the result of an SQL query in Node.js without using braces

As a beginner in node.js with only a basic understanding of javascript, I apologize if I make any mistakes. I attempted to display the results retrieved by an SQL query in node.js using: <p>Users are " + util.inspect(results) + ".</p>" an ...

Tips for searching for JSON objects in a PostgreSQL table by a specific element property?

I'm working with a table named "test" that has a json field called "description." My goal is to filter the table and retrieve only the json elements from the "description" where status = inUse. Does anyone know of a more efficient way to extract, fil ...

sidebar that appears upon the initial page load

I'm currently working on implementing a sidebar navigation panel for my website using JavaScript, HTML, and CSS. However, I am facing an issue where the sidebar automatically opens when the page is first loaded, even before clicking on the icon to ope ...

Begin a SeleniumWebDriver session after Google Chrome has been launched beforehand

I am looking to create an automation using SeleniumWebDriver and Node.js, but I am facing an issue where I cannot start the automation if Google Chrome is already open and in use by the user. Currently, my workaround is to close all instances of Chrome be ...

When combining CSS grids, nesting them can sometimes cause issues with the height layout

Check out the code on jsFiddle .component-container { width: 800px; height: 200px; background-color: lightyellow; border: 1px solid red; padding: 10px; overflow: hidden; } .component-container .grid-container-1 { display: grid; grid-tem ...

Learn the process of transmitting data from middleware to components and APIs in Next.js version 13

I've been experimenting with the Next Js 13 middleware feature and I'm a bit confused about how to pass data from the middleware to components/pages/api. For example, when trying to pass payload data or determine who the currently logged-in user ...

The type check for the "list" prop failed while passing a JSON array. The expected type was an Array, but a String was received instead

I am encountering an issue with a json object, named jsonObject, that includes an array labeled tracks. I have been using this.jsonObject.tracks as an array in my methods and template (with v-for) without any issues in Vue. However, I am facing a problem w ...

Explore the full range of events available on the Angular UI-Calendar, the innovative directive designed for Arshaw FullCalendar

Utilizing external events with Angular ui-calendar: HTML: <div id='external-events'> <ul> <li class='fc-event'>Event 1</li> <li class='fc-event'>Event 2< ...