Giter Club home page Giter Club logo

Comments (10)

ntkme avatar ntkme commented on June 3, 2024 1

It's the child_io who needs to be patched, rather than the parent_io. The return value of popen3 is parent_io. Therefore, popen3 has to be patched internally.

from sass-embedded-host-ruby.

ntkme avatar ntkme commented on June 3, 2024

I have to take a more detailed look but most likely JDK21 + JRuby issue with stdio handling in the open3 gem.

The code path that Dart VM ran into issue is where it’s trying to write its stdout to send response back to Ruby side. - This means at least the Dart VM received the request properly, so that sprockets, sassc-embedded, sass-embedded, and protobuf are all likely working.

The stdout of a child process can get stuck if the polling thread from the parent process is not working properly. If the stdout pipe buffer is completely full, and the parent process is not consuming the buffer at all, the whole child process can get stuck.

from sass-embedded-host-ruby.

ntkme avatar ntkme commented on June 3, 2024

@chadlwilson Also, was it on windows or unix-like, or both? JRuby has different I/O implementation for open3 on windows and unix-like.

from sass-embedded-host-ruby.

chadlwilson avatar chadlwilson commented on June 3, 2024

This was on MacOS Sonoma 14.5 (sorry, updated description) but I can give it a go on Linux if that helps (sounds like probably roughly the same behaviour expected though?).

I haven't yet attempted on Windows; usually that's the "final frontier" :D

from sass-embedded-host-ruby.

chadlwilson avatar chadlwilson commented on June 3, 2024

Hmm, could it be jruby/jruby#8235 or jruby/jruby#8069 or jruby/jruby#8234 ?

from sass-embedded-host-ruby.

ntkme avatar ntkme commented on June 3, 2024

I can reproduce this in CI with the following code:

    10000.times do |i|
      Sass.compile_string('a{b:c}' * i).css
      puts i
    end

On windows it works to the end. However on unix-like, this works until the 4368th iteration but fails at the 4369th iteration.

On the 4368th iteration, the size of protobuf reply message is 65530 bytes, and on the 4369th iteration the size of reply message is 65545 bytes.

require 'sass-embedded'

Sass.compile_string('a{b:c}' * 4368).css # works, stdout reply size is 65530 bytes
Sass.compile_string('a{b:c}' * 4369).css # fails, stdout reply size is 65545 bytes.

It must be jruby/jruby#8235.

from sass-embedded-host-ruby.

chadlwilson avatar chadlwilson commented on June 3, 2024

OK, will close this for now and track there. Thanks for the effort, as always!

from sass-embedded-host-ruby.

chadlwilson avatar chadlwilson commented on June 3, 2024

I tried to monkey patch the Connection class and streams as in jruby/jruby#8235 (comment) but my Ruby and monkey-patching abilities are probably a bit too limited for that one :)

from sass-embedded-host-ruby.

ntkme avatar ntkme commented on June 3, 2024
# frozen_string_literal: true

require 'fcntl'

module Open3
  _popen_run = instance_method(:popen_run)
  define_method(:popen_run) do |cmd, opts, child_io, parent_io, &block|
    child_io.each do |io|
      flags = io.fcntl(Fcntl::F_GETFL)
      io.fcntl(Fcntl::F_SETFL, flags | (Fcntl::O_NONBLOCK))
      io.fcntl(Fcntl::F_SETFL, flags & (~Fcntl::O_NONBLOCK))
    end
    _popen_run.bind(self).call(cmd, opts, child_io, parent_io, &block)
  end
  module_function :popen_run
  class << self
    private :popen_run
  end
end

from sass-embedded-host-ruby.

chadlwilson avatar chadlwilson commented on June 3, 2024

Works like a dream! Didn't think of trying to monkey patch popen directly.

from sass-embedded-host-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.