Comments (8)
//> using scala 3.3.3
import java.io.*
case class Message(content: String):
lazy val bomb: String =
Thread.sleep(200)
"BOMB: " + content
def serialize(obj: Message): Array[Byte] =
val byteStream = ByteArrayOutputStream()
val objectStream = ObjectOutputStream(byteStream)
try
objectStream.writeObject(obj)
byteStream.toByteArray
finally
objectStream.close()
byteStream.close()
def deserialize(bytes: Array[Byte]): Message =
val byteStream = ByteArrayInputStream(bytes)
val objectStream = ObjectInputStream(byteStream)
try
objectStream.readObject().asInstanceOf[Message]
finally
objectStream.close()
byteStream.close()
@main def main =
val bytes = locally:
val msg = Message("test")
val touch = Thread(() => {
msg.bomb // start evaluation before serialization
()
})
touch.start()
Thread.sleep(50) // give some time for the fork to start lazy val rhs eval
serialize(msg) // serialize in the meantime so that we capture Waiting state
val deserializedMsg = deserialize(bytes)
@volatile var msg = ""
@volatile var started = false
val read = Thread(() => {
started = true
msg = deserializedMsg.bomb
()
})
read.start()
Thread.sleep(1000)
if !started then throw Exception("wtf")
if !msg.isBlank then println(s"succeeded: $msg")
else
read.interrupt()
println("failed to read bomb in 1s!")
from scala3.
This is probably impossible to test correctly on our CI.
Once it is fixed, I suggest adding the reproducer repo to the community build. We can run two first steps from the readme with some predefined timeout, to test if the problem is fixed.
@WojciechMazur will this require significant changes to the OCB?
from scala3.
will this require significant changes to the OCB?
No, it should be really straightforward. All we need is to include the reproducer repo in the OpenCB config https://github.com/VirtusLab/community-build3/blob/master/coordinator/configs/custom-projects.txt
from scala3.
This could be simplified further to serialize to binary file but it would still require two jvms. Would that fit to CI?
from scala3.
Having it just compile will test nothing and with the current shape of the code it just hangs on one thread, there are no assertions as it's just demonstrating the problem. I think it can be greatly simplified (no akka for starters) and incorporated into the test suite of the language instead of OCB.
from scala3.
//> using scala 3.3.3
//> using jvm 21
//> using dep com.softwaremill.ox::core:0.2.2
import java.io.*
import ox.*
import scala.concurrent.duration.*
case class Message(content: String):
lazy val bomb: String =
sleep(200.millis)
"BOMB: " + content
def serialize(obj: Message): Array[Byte] =
val byteStream = ByteArrayOutputStream()
val objectStream = ObjectOutputStream(byteStream)
try
objectStream.writeObject(obj)
byteStream.toByteArray
finally
objectStream.close()
byteStream.close()
def deserialize(bytes: Array[Byte]): Message =
val byteStream = ByteArrayInputStream(bytes)
val objectStream = ObjectInputStream(byteStream)
try
objectStream.readObject().asInstanceOf[Message]
finally
objectStream.close()
byteStream.close()
@main def main =
val bytes = supervised:
val msg = Message("test")
fork:
msg.bomb // start evaluation before serialization
sleep(50.millis) // give some time for the fork to start lazy val rhs eval
serialize(msg) // serialize in the meantime so that we capture Waiting state
val deserializedMsg = deserialize(bytes)
unsupervised:
@volatile var msg = ""
val f = forkCancellable:
msg = deserializedMsg.bomb
sleep(1000.millis)
if !msg.isBlank then println(s"succeeded: $msg")
else
f.cancel()
println("failed to read bomb in 1s!")
from scala3.
arguably can be done without ox and jdk 21 :D one second please
from scala3.
This even shows the nice stack trace from CountDownLatch#await()
:
Exception in thread "Thread-1" java.lang.InterruptedException
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1100)
at java.base/java.util.concurrent.CountDownLatch.await(CountDownLatch.java:230)
at Message.bomb$lzyINIT1(main.scala:8)
at Message.bomb(main.scala:7)
at main$package$.$anonfun$2(main.scala:49)
at java.base/java.lang.Thread.run(Thread.java:1583)
failed to read bomb in 1s!
from scala3.
Related Issues (20)
- 3.5.0-RC7 Release procedure HOT 1
- "method apply must be called with () argument" must be generated for scala.Function0 HOT 5
- Regression in `softwaremill/tapir` - StaleSymbolException when compiling macros
- type variable resolution contradicts language spec in a case of an inner class extending an outer class HOT 1
- static final null character crashes parser HOT 1
- quoted Symbol.spliceOwner should not be the current class in extends clauses
- Unexpected type representation reached the compiler backend
- a type defined in a trait is "not found" in an object that extends the trait (under certain circumstances) HOT 1
- Anonymous givens for two different types with same name create "Duplicate definition" HOT 1
- Unexpected warning when `@main` is used twice within a single object HOT 2
- Match type with opaque type among cases does not resolve HOT 1
- Cannot do a map on a Map with Scala 3, with Scala 2.13 it works ok HOT 6
- 3.5.0 & 3.5.1-RC2 Release procedure HOT 2
- -Yexplicit-nulls fails to detect null pointer dereference HOT 2
- `-indent` `-rewrite` can produce inparsable code for curried methods taking triple-quote arguments HOT 1
- assertion failed: position not set for new com.augustnagro.magnum.SqlName # -1 of class dotty.tools.dotc.ast.Trees$Select
- 3.4.3 Release procedure HOT 1
- Need a way to specify a method's charging a capture set parameter
- Match type fails to reduce when it doesn't look like it needs to reduce
- Nil and LinearSeq cannot be compared
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scala3.