Skip to content

Router with 6 Dealers creates a SIGABORT failure #4783

@flajann2

Description

@flajann2

OS: Arch Linux

OS: Arch Linux x86_64
Host: NH50_70RA
Kernel: Linux 6.9.7-arch1-1
Uptime: 3 days, 7 hours, 58 mins
Packages: 2670 (pacman), 944 (nix-user), 370 (nix-default), 37 (flatpak)
Shell: fish 4.0.1
Display (HISENSE): 3840x2160 @ 30 Hz in 52" [External]
WM: Hyprland (Wayland)
Theme: Breeze-Dark [GTK2/3]
Icons: breeze-dark [GTK2/3/4]
Font: Noto Sans (10pt) [GTK2/3/4]
Cursor: Oxygen_Blue (24px)
Terminal: kitty 0.40.1
Terminal Font: NotoSansMono-Regular (9pt)
CPU: Intel(R) Core(TM) i5-9300H (8) @ 4.10 GHz
GPU 1: NVIDIA GeForce GTX 1650 Mobile / Max-Q [Discrete]
GPU 2: Intel UHD Graphics 630 @ 1.05 GHz [Integrated]
Memory: 27.87 GiB / 31.19 GiB (89%)
Swap: Disabled
Disk (/): 1.47 TiB / 1.82 TiB (81%) - btrfs
Disk (/miloba): 128.00 KiB / 1.01 TiB (0%) - zfs
Local IP (br0): 192.168.0.195/24
Battery (BAT): 100% [AC Connected]
Locale: en_US.UTF-8

    Assertion failed: !_current_out (/usr/src/debug/zeromq/zeromq/src/router.cpp:166)
     fish: Job 1, 'cabal run playground-zmq-router' terminated by signal SIGABRT (Abort)

Image

-- ZRouter.hs
{-# LANGUAGE OverloadedStrings #-}
module Main where

import System.ZMQ4
import Control.Monad
import Control.Concurrent
import Control.Concurrent.STM
import Data.ByteString.Char8 (unpack, ByteString)
import qualified Data.Set as Set
import Data.List.NonEmpty (NonEmpty(..))

main :: IO ()
main = withContext $ \ctx -> do
    withSocket ctx Router $ \router -> do
      bind router "tcp://*:5555"
      clientsVar <- newTVarIO Set.empty
        
      -- Broadcast thread
      _ <- forkIO $ broadcastLoop router clientsVar
        
      -- Main receive loop
      forever $ do
        msg <- receiveMulti router
        case msg of
          [identity', content] -> do
            atomically $ modifyTVar clientsVar (Set.insert identity')
            putStrLn $ "Received: " ++ unpack content
            sendMulti router (identity' :| ["ACK"])
          _ -> putStrLn "Invalid message format"

broadcastLoop :: Socket Router -> TVar (Set.Set ByteString) -> IO ()
broadcastLoop router clientsVar = forever $ do
    threadDelay 100000  -- 0.1 seconds
    clients <- atomically $ readTVar clientsVar
    mapM_ (\clientId -> sendMulti router (clientId :| ["START"])) (Set.toList clients)
    -- putStrLn "Broadcasted START to all clients"

-- ZDealer.hs
{-# LANGUAGE OverloadedStrings #-}

module Main where

import System.IO
import System.Exit
import System.Environment
import System.ZMQ4
import Control.Monad
import Data.String
import Data.ByteString.Char8 (pack, unpack)
import Data.Restricted ()

main :: IO ()
main = withContext $ \ctx -> do
  args <- getArgs
  when (length args /= 1) $ do
      hPutStrLn stderr "usage: prompt <uniqueID>"
      exitFailure
  let uniqID = head args
  withSocket ctx Dealer $ \dealer ->
    do
      setIdentity (restrict (pack uniqID)) dealer
      connect dealer "tcp://localhost:5555"
        
      -- Send initial message
      send dealer [] $ pack $ "Hello from " <> uniqID
        
      -- Receive loop
      let recvLooper i = do
            response <- receive dealer
            case unpack response of
              "ACK"   -> putStrLn "Server acknowledged"
              "START" -> do
                putStrLn $ "Starting data transmission " <> show i <> "..."
                send dealer [] $ pack $ "PAYLOAD(" <> uniqID <> "): " <> show i
              _       -> putStrLn $ "Received: " <> unpack response
            recvLooper $ i+1
      recvLooper 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions