!EoyccMaVGwdqyfKMAL:matrix.org

Nim Web Development

6262 Members
A channel to talk about web development with Nim.27 Servers

Load older messages


SenderMessageTime
20 Jan 2025
@_discord_138279121586225152:t2bot.ioangelsdust You don't want the asynchttp server being exposed directly to the internet as WSGI server, so you use candy or nginx or even apache 07:17:15
@_discord_532997111273226259:t2bot.ioinfohazrd_ changed their display name from infohazard_ to infohazrd_.13:15:39
@gudzerataras:matrix.orggudzerataras joined the room.15:53:39
@_discord_102899813149855744:t2bot.ioajusa I've been using Caddy + Mummy for my personal projects, highly recommend 19:45:53
@_discord_153300788976812032:t2bot.iomjsdev Yeah, I used caddy... I'll look into Mummy, route parameterization seems limited? 19:49:45
@_discord_102899813149855744:t2bot.ioajusa You can do path parameters, pretty sure there's an example. 21:21:05
@_discord_102899813149855744:t2bot.ioajusa Eg GET /users/:userId is supported through the router 21:21:29
@_discord_794425897561489440:t2bot.ioxvexx joined the room.23:28:05
21 Jan 2025
@_discord_1318396538027773962:t2bot.iosysglitch_46552 joined the room.05:13:26
@_discord_801227226749599754:t2bot.ioyummy_licorice changed their profile picture.19:44:42
@henrique21:matrix.org@henrique21:matrix.org joined the room.21:13:27
@henrique21:matrix.org@henrique21:matrix.org left the room.21:18:46
22 Jan 2025
@_discord_337978877421027329:t2bot.ionimble install python.zig? changed their display name from @@prestosilver to nimble install python.zig?.00:28:09
@_discord_1260504658519261194:t2bot.iozancodm. joined the room.00:55:47
@_discord_690342851711860857:t2bot.ioclifzz joined the room.01:07:38
@_discord_338652997317951488:t2bot.ioluckyhits_ joined the room.03:37:26
@_discord_123539225919488000:t2bot.ioanuke changed their profile picture.05:08:50
@_discord_1147867292860960768:t2bot.iosmarterandsmarter joined the room.05:22:34
@_discord_1331518030076710967:t2bot.iom1l0js_20119 joined the room.06:57:57
@_discord_1328711122349461592:t2bot.iobritannia.zeta joined the room.15:17:37
23 Jan 2025
@_discord_419925691832991754:t2bot.iouser2m does nayone have a socket pool / broadcast implementation?
I have an app with a bunch of websockets in different chatrooms and I'm trying to manage them.
But my app doesn't seem to be closing socket connections and I think it might be my socket pool / broadcast
implementation. Apologies for the long text
02:39:05
@_discord_419925691832991754:t2bot.iouser2m
type ConnectionPool* = ref object
    connections* : seq[WebSocket]
    lock*        : Lock

proc newConnectionPool*(): ConnectionPool =
    result = ConnectionPool(connections: @[])
    result.lock.initLock()

var socket_pool = initTable[string, var ConnectionPool]()

proc removeConnection(session_id: string, closed_socket: WebSocket) {.gcsafe.} =
    icb "Removing socket from " & session_id & " connection pool"
    var
        num_connections_before : int
        num_connections_after  : int
    
    {.cast(gcsafe).}: 
        num_connections_before = socket_pool[session_id].connections.len
        icb "Num connections before removal: " & $num_connections_before

        withLock socket_pool[session_id].lock:
            socket_pool[session_id].connections = 
                socket_pool[session_id].connections
                    .filterit( it != closed_socket )

        num_connections_after = socket_pool[session_id].connections.len
        icb "Num connections after removal: " & $num_connections_after

        if num_connections_after != num_connections_before - 1:
            echo "Error removing socket from connection pool"
            echo "Num connections before removal: " & $num_connections_before
            echo "Num connections after removal: " & $num_connections_after
02:39:25
@_discord_419925691832991754:t2bot.iouser2m
proc broadcastMessage(session_id: string, message: string) {.async.} =
    var connectionsToSend, failedConnections: seq[WebSocket] = @[]

    # Extract the relevant WebSocket connections while holding the lock
    {.cast(gcsafe).}:
        withLock socket_pool[session_id].lock:
            for ws in socket_pool[session_id].connections:
                if ws.readyState == Open:
                    connectionsToSend.add(ws)

    icb "Num sockets in connection pool for broadcast: " & $connectionsToSend.len

    # Send messages and handle exceptions
    for ws in connectionsToSend:
        try:
            await ws.send(message)
        except:
            icr "Error sending message to websocket; removing from pool."
            failedConnections.add(ws)

    # Remove failed connections
    for ws in failedConnections:
        removeConnection(session_id, ws)
        try:
            ws.close()
        except:
            discard
02:39:37
@_discord_532751332445257729:t2bot.iothat_dude. changed their profile picture.03:21:14
@_discord_162571170904801280:t2bot.ioblackmius ask AI 03:45:36
@_discord_419925691832991754:t2bot.iouser2m I did many times lol I can't seem to figure out the isse 05:31:48
@_discord_419925691832991754:t2bot.iouser2m Issue 05:31:51
@_discord_222150919863664640:t2bot.iomonkey085395 changed their profile picture.05:54:22
@_discord_258079305261645825:t2bot.ionitely_ that code does not look thread safe. But idk if that's why sockets don't get closed 08:23:58
@_discord_162571170904801280:t2bot.ioblackmius read how readyState == Closed set

the treeforms library sets close state on recvFrame or send

you are checking close state before calling send so
10:04:07

There are no newer messages yet.


Back to Room ListRoom Version: 6