0

I'm running into an issue where attempting to run code on IBM's Swift Sandbox is causing some sort of internal timeout.

Swift Ver. 3.0.1 (Release)
Platform: Linux (x86_64)
Error running code: 
WARNING: Your kernel does not support swap limit capabilities, memory limited without swap.
/swiftfiles/doit.sh: line 51:    42 Illegal instruction     timeout ${TIMEOUT} .build/debug/TempCode

The code in question is decoding a large Base64 encoding String:

let base64EncodedInput = [really really long string]

let inputData = Data(base64Encoded: base64EncodedInput)!

let inputDecodedString = String(data: inputData, encoding: .utf8)!

let rowArray = inputDecodedString.components(separatedBy: "\n")

You can see the full data string and run the code online here.

Am I maxing out the time allocated to run my Swift process? What is the timeout?

JAL
  • 41,701
  • 23
  • 172
  • 300
  • We have I believe a ten-second timeout now, but that's not what our timeout message looks like. The message you're seeing indicates that some illegal code is being run, but the full error message might be suppressed. I will take a deeper look at this and get back to you. – TheSoundDefense Dec 04 '16 at 21:10
  • @TheSoundDefense Thanks for looking into this. I was playing around with the input and got a different error this time: [gist](https://gist.github.com/JALsnipe/4e3f1a833701b1d84eedbddbec39f693) – JAL Dec 05 '16 at 03:39
  • This may be a server issue and not necessarily something wrong with your code. I'll have to take a look. – TheSoundDefense Dec 05 '16 at 06:17
  • @TheSoundDefense Thanks. Is there a better place to report such issues (maybe an IBM JIRA board or something)? Or should I continue to use the [tag:ibm-swift-sandbox] tag. – JAL Dec 05 '16 at 15:26
  • At the top of the Sandbox page is a Feedback link where you can report things like bugs, if you know that they are bugs. It requires an IBM developerWorks account at the moment, though. – TheSoundDefense Dec 05 '16 at 15:36

1 Answers1

1

To answer the question in the title, we've implemented a hard timeout of ten seconds, though code may be killed faster if memory runs out or the stack overflows. But that's not quite the issue you're seeing here.

After a bit of investigation, we determined that the base 64 encoding service that created the very large string in your Sandbox link used \r\n for newlines instead of \n. This causes an error when you use let rowArray = inputDecodedString.components(separatedBy: "\n") due to what appears to be a bug in Foundation. If you instead use let rowArray = inputDecodedString.components(separatedBy: "\r\n") you should see your issue disappear. We'll be filing an issue with Foundation in the meantime.

The reason you see timeout is because we're returning a not-so-great error message. The line timeout ${TIMEOUT} .build/debug/TempCode is part of how we execute a Sandbox user's code, and when that line failed we returned it as part of the error message. We'll work on a less confusing error message for the future.

EDIT: it turns out that this is a known bug. https://bugs.swift.org/browse/SR-2483

TheSoundDefense
  • 6,753
  • 1
  • 30
  • 42
  • Thanks, this is very helpful. Please link to the ticket you open on https://bugs.swift.org here so I can watch the issue. – JAL Dec 05 '16 at 17:59