2

I'm running a few legacy databases in an Azure SQL Edge docker container instance on an M1 Macbook and it consistently crashes when running a user defined function. This function makes a cross database SELECT statement to retrieve some data for calculations.

The crash log:

2023-07-20 12:10:54 Ubuntu 18.04.6 LTS
2023-07-20 12:10:54 Capturing core dump and information to /var/opt/mssql/log...
2023-07-20 12:10:49 Sphr [ERROR] Unable to dispatch SIGSEGV: function has no hardware exception context (Runtime.cpp:1368)
2023-07-20 12:10:49 This program has encountered a fatal error and cannot continue running at Thu Jul 20 16:10:49 2023
2023-07-20 12:10:49 The following diagnostic information is available:
2023-07-20 12:10:49 
2023-07-20 12:10:49          Reason: 0x00000001
2023-07-20 12:10:49          Signal: SIGSEGV - Segmentation fault (11)
2023-07-20 12:10:49           Stack:
2023-07-20 12:10:49                  IP               Function
2023-07-20 12:10:49                  ---------------- --------------------------------------
2023-07-20 12:10:49                  0000aaaaba24ba70 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::~_Sp_counted_base()+0x25d0
2023-07-20 12:10:49                  0000aaaaba24b618 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::~_Sp_counted_base()+0x2178
2023-07-20 12:10:49                  0000aaaaba30b7fc std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_
2023-07-20 12:10:49                  0000aaaaba25f1b0 std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::~_Sp_counted_base()+0x15d10
2023-07-20 12:10:49                  0000ffffb67e7790 <unknown>
2023-07-20 12:10:49                  0000ffff9a190f58 S_SbtUnimplementedInstruction+0x4a3120
2023-07-20 12:10:49                  0000ffff95ff615c _init+0x106073c
2023-07-20 12:10:49                  0000ffff95ff4a54 _init+0x105f034
2023-07-20 12:10:49                  0000ffff95ff0d14 _init+0x105b2f4
2023-07-20 12:10:49                  0000ffff95b4c52c _init+0xbb6b0c
2023-07-20 12:10:49                  0000ffff96dcee20 _init+0x1e39400
2023-07-20 12:10:49                  0000ffff976b226c _init+0x271c84c
2023-07-20 12:10:49                  0000ffff96296058 _init+0x1300638
2023-07-20 12:10:49                  0000ffff9629f0d0 _init+0x13096b0
2023-07-20 12:10:49                  0000ffff9602b8f4 _init+0x1095ed4
2023-07-20 12:10:49                  0000ffff961ebec0 _init+0x12564a0
2023-07-20 12:10:49                  0000ffff961e9f3c _init+0x125451c
2023-07-20 12:10:49                  0000ffff961e1ed8 _init+0x124c4b8
2023-07-20 12:10:49                  0000ffff961e77fc _init+0x1251ddc
2023-07-20 12:10:49                  0000ffff95d2dd1c _init+0xd982fc
2023-07-20 12:10:49                  0000ffff95dffbf8 _init+0xe6a1d8
2023-07-20 12:10:49                  0000ffff95e0017c _init+0xe6a75c
2023-07-20 12:10:49                  0000ffffa341a1f8 S_SbtUnimplementedInstruction+0x887f8
2023-07-20 12:10:49         Process: 27 - sqlservr
2023-07-20 12:10:49          Thread: 156 (application thread 0x1f4)
2023-07-20 12:10:49     Instance Id: 0ae125d0-f6de-487a-8626-4e09946fd9d9
2023-07-20 12:10:49        Crash Id: 29e3d97b-fc09-48da-b544-4ecfbd4d0e41
2023-07-20 12:10:49     Build stamp: 7e3b976a7614e3cb6d16ce08aa8e3b28924df7f1870dfe9956e396a15452340b
2023-07-20 12:10:49    Distribution: Ubuntu 18.04.6 LTS aarch64
2023-07-20 12:10:49      Processors: 4
2023-07-20 12:10:49    Total Memory: 8232951808 bytes
2023-07-20 12:10:49       Timestamp: Thu Jul 20 16:10:49 2023
2023-07-20 12:10:49      Last errno: 11
2023-07-20 12:10:49 Last errno text: Resource temporarily unavailable

The function looks like this:

CREATE FUNCTION [dbo].[GetLimit]
(
  @id INT
)
RETURNS INT
AS
BEGIN
  DECLARE @result INT

  SET @result = dbo.MinNumber(ISNULL((SELECT Limit FROM [OtherDatabase].dbo.SomeTable WHERE Id = @id), 1000000), (SELECT TOP 1 Limit FROM Settings))

  RETURN @result
ENDI

dbo.MinNumber is another function that only returns the smaller number of two numbers.

edit: The function looks like this:

CREATE FUNCTION [dbo].[MinNumber] (@number1 INT, @number2 INT)
RETURNS INT AS 
BEGIN
  DECLARE @result INT
  SET @result = CASE WHEN @number1 < @number2 THEN @number1 ELSE @number2 END
  RETURN @result END

I've tried to stop using MinNumber and make the comparison directly but it still crashes.

The strange thing is if I replace the cross db SELECT statement with a variable that's declared and set first, it doesn't crash.

Example:

DECLARE @result INT
DECLARE @num1 INT = ISNULL((SELECT Limit FROM [OtherDatabase].dbo.SomeTable WHERE Id = @id), 1000000)
SET @result = dbo.MinNumber(@num1, (SELECT TOP 1 Limit FROM Settings))

RETURN @result

Even thought I know modifying it like this works, I would prefer not use this solution since the existing function works perfectly fine in our production SQL Server environment so I don't want to have to maintain a different version of a UDF per environment.

Has anyone else come across this particular error or situation?

Al Ma
  • 21
  • 2
  • That function also calls another UDF. We need the definitions for both really. Though that query on its own doesn't look too performant. – Thom A Jul 20 '23 at 18:50
  • Seems like a bug. No combinations of functions should lead to signaled exceptions – siggemannen Jul 20 '23 at 19:00
  • You could still rewrite the function so it both looks and works the same for both environments – siggemannen Jul 20 '23 at 19:01
  • @ThomA The other function looks like this: `CREATE FUNCTION [dbo].[MinNumber] ( @number1 INT ,@number2 INT ) RETURNS INT AS BEGIN DECLARE @result INT SET @result = CASE WHEN @number1 < @number2 THEN @number1 ELSE @number2 END RETURN @result END` – Al Ma Jul 20 '23 at 19:27
  • [Edit] your question, @AlMa . – Thom A Jul 20 '23 at 19:41
  • (SELECT TOP 1 Limit FROM Settings) - i wonder if that's the issue. Ideally, it should have an ORDER BY me thinks – siggemannen Jul 21 '23 at 11:26

0 Answers0