|
| 1 | +import React, { useEffect, useState } from 'react'; |
| 2 | +import { ServerContext } from '@/state/server'; |
| 3 | +import Modal from '@/components/elements/Modal'; |
| 4 | +import tw from 'twin.macro'; |
| 5 | +import Button from '@/components/elements/Button'; |
| 6 | +import FlashMessageRender from '@/components/FlashMessageRender'; |
| 7 | +import useFlash from '@/plugins/useFlash'; |
| 8 | +import { SocketEvent } from '@/components/server/events'; |
| 9 | +import { useStoreState } from 'easy-peasy'; |
| 10 | +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
| 11 | +import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'; |
| 12 | + |
| 13 | +const PIDLimitModalFeature = () => { |
| 14 | + const [ visible, setVisible ] = useState(false); |
| 15 | + const [ loading ] = useState(false); |
| 16 | + |
| 17 | + const status = ServerContext.useStoreState(state => state.status.value); |
| 18 | + const { clearFlashes } = useFlash(); |
| 19 | + const { connected, instance } = ServerContext.useStoreState(state => state.socket); |
| 20 | + const isAdmin = useStoreState(state => state.user.data!.rootAdmin); |
| 21 | + |
| 22 | + useEffect(() => { |
| 23 | + if (!connected || !instance || status === 'running') return; |
| 24 | + |
| 25 | + const errors = [ |
| 26 | + 'pthread_create failed', |
| 27 | + 'Exception in thread "Craft Async Scheduler Management Thread"', |
| 28 | + 'unable to create new native thread', |
| 29 | + 'unable to create native thread', |
| 30 | + ]; |
| 31 | + |
| 32 | + const listener = (line: string) => { |
| 33 | + if (errors.some(p => line.toLowerCase().includes(p))) { |
| 34 | + setVisible(true); |
| 35 | + } |
| 36 | + }; |
| 37 | + |
| 38 | + instance.addListener(SocketEvent.CONSOLE_OUTPUT, listener); |
| 39 | + |
| 40 | + return () => { |
| 41 | + instance.removeListener(SocketEvent.CONSOLE_OUTPUT, listener); |
| 42 | + }; |
| 43 | + }, [ connected, instance, status ]); |
| 44 | + |
| 45 | + useEffect(() => { |
| 46 | + clearFlashes('feature:pidLimit'); |
| 47 | + }, []); |
| 48 | + |
| 49 | + return ( |
| 50 | + <Modal visible={visible} onDismissed={() => setVisible(false)} closeOnBackground={false} showSpinnerOverlay={loading}> |
| 51 | + <FlashMessageRender key={'feature:pidLimit'} css={tw`mb-4`} /> |
| 52 | + {isAdmin ? |
| 53 | + <> |
| 54 | + <div css={tw`mt-4 sm:flex items-center`}> |
| 55 | + <FontAwesomeIcon css={tw`pr-4`} icon={faExclamationTriangle} color={'orange'} size={'4x'}/> |
| 56 | + <h2 css={tw`text-2xl mb-4 text-neutral-100 `}>Memory or process limit reached...</h2> |
| 57 | + </div> |
| 58 | + <p css={tw`mt-4`}>This server has reached the maximum process or memory limit.</p> |
| 59 | + <p css={tw`mt-4`}>Increasing <code css={tw`font-mono bg-neutral-900`}>container_pid_limit</code> in the wings configuration, <code css={tw`font-mono bg-neutral-900`}>config.yml</code>, might help resolve this issue.</p> |
| 60 | + <p css={tw`mt-4`}><b>Note: Wings must be restarted for the configuration file changes to take effect</b></p> |
| 61 | + <div css={tw`mt-8 sm:flex items-center justify-end`}> |
| 62 | + <Button onClick={() => setVisible(false)} css={tw`w-full sm:w-auto border-transparent`}> |
| 63 | + Close |
| 64 | + </Button> |
| 65 | + </div> |
| 66 | + </> |
| 67 | + : |
| 68 | + <> |
| 69 | + <div css={tw`mt-4 sm:flex items-center`}> |
| 70 | + <FontAwesomeIcon css={tw`pr-4`} icon={faExclamationTriangle} color={'orange'} size={'4x'}/> |
| 71 | + <h2 css={tw`text-2xl mb-4 text-neutral-100`}>Possible resource limit reached...</h2> |
| 72 | + </div> |
| 73 | + <p css={tw`mt-4`}>This server is attempting to use more resources than allocated. Please contact the administrator and give them the error below.</p> |
| 74 | + <p css={tw`mt-4`}><code css={tw`font-mono bg-neutral-900`}>pthread_create failed, Possibly out of memory or process/resource limits reached</code></p> |
| 75 | + <div css={tw`mt-8 sm:flex items-center justify-end`}> |
| 76 | + <Button onClick={() => setVisible(false)} css={tw`w-full sm:w-auto border-transparent`}> |
| 77 | + Close |
| 78 | + </Button> |
| 79 | + </div> |
| 80 | + </> |
| 81 | + } |
| 82 | + </Modal> |
| 83 | + ); |
| 84 | +}; |
| 85 | + |
| 86 | +export default PIDLimitModalFeature; |
0 commit comments